repair script hanging

This commit is contained in:
Manuel Weiser 2018-08-06 16:07:24 +02:00
parent 906340484d
commit a480476b64
8 changed files with 54 additions and 54 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
Body.stl

Binary file not shown.

Binary file not shown.

View File

@ -12,3 +12,6 @@
platform = espressif8266
board = esp12e
framework = arduino
upload_port = esp_wz_duft.local ;192.168.1.134
upload_flags = --auth=druffmann77

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

View File

@ -2,7 +2,8 @@
#include <Arduino.h>
#include <ESP8266WiFi.h> //ESP library from http://github.com/esp8266/Arduino
#include <PubSubClient.h> // MQTT library from http://github.com/Imroy/pubsubclient
#include "Servo.h"
#include <Servo.h>
#include <ArduinoOTA.h>
extern "C" {
#include "user_interface.h"
@ -11,45 +12,25 @@ extern "C" {
String esp_id = "duft";
const char *ssid = "iApfel"; // cannot be longer than 32 characters!
const char *password = "***PASSWORD***"; //
const char *password = "druffmann77"; //
const char* mqtt_server = "192.168.1.5";
const char* ota_password = "druffmann77";
#define SERV1 12 // Pin connected to the Servomotor
Servo s1;
// Strings zusammen bauen
String esp = "esp_wz" + esp_id;
String esp = "esp_wz_" + esp_id;
char *esp_name = &esp[0u];
//String air_topic = "esp" + String(esp_id) + "/room";
//const char* mqtt_air_topic = &air_topic[0u];
const char* mqtt_air_topic = "airfresh";
String print_topic = "airfresh";
const char* mqtt_print_topic = &print_topic[0u];
WiFiClient espClient;
PubSubClient client(espClient);
void setup() {
// start the serial connection
Serial.begin(115200);
setup_wifi();
Serial.print("Connecting to MQTT");
client.setServer(mqtt_server, 1883);
Serial.print("Connected to MQTT");
client.setCallback(callback);
client.publish("airfrash","hello world");
client.subscribe("airfresh");
// move servomotor to neutral position
s1.attach(SERV1);
delay(400);
s1.write(90);
delay(400);
s1.detach();
}
void setup_wifi() {
delay(10);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
//wifi_set_phy_mode(PHY_MODE_11G);
@ -66,8 +47,8 @@ void setup_wifi() {
// animate LEDs while waiting for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
delay(50);
}
Serial.println("");
@ -76,30 +57,41 @@ void setup_wifi() {
Serial.println(WiFi.localIP());
}
void loop() {
// Check WLan
if (WiFi.status() != WL_CONNECTED) {
reconnect();
}
void setup() {
// start the serial connection
Serial.begin(115200);
// Check mqtt messages
if (!client.connected()) {
reconnect();
}
client.loop();
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
ArduinoOTA.setPassword(ota_password);
ArduinoOTA.setHostname(esp_name);
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
});
ArduinoOTA.begin();
// move servomotor to neutral position
s1.attach(SERV1);
s1.write(90);
delay(3000);
s1.detach();
}
// this function is called whenever a message
// is received from Adafruit IO. it was attached to
// the feed in the setup() function above.
void callback(char* topic, byte* payload, unsigned int length) {
// Zähler
int i = 0;
// Hilfsvariablen für die Convertierung der Nachricht in ein String
char message_buff[100];
Serial.println("Message arrived: topic: " + String(topic));
Serial.println("Length: " + String(length,DEC));
//Serial.println("Message arrived: topic: " + String(topic));
//Serial.println("Length: " + String(length,DEC));
// Kopieren der Nachricht und erstellen eines Bytes mit abschließender \0
for(i=0; i<length; i++) {
@ -109,34 +101,30 @@ void callback(char* topic, byte* payload, unsigned int length) {
// Konvertierung der nachricht in ein String
String msgString = String(message_buff);
Serial.println("Payload: " + msgString);
//Serial.println("Payload: " + msgString);
// if virtual push button was pressed
if (msgString.equalsIgnoreCase("1")){
Serial.println("Virtual push button");
s1.attach(SERV1);
delay(400);
s1.write(55);
s1.write(60);
delay(1000);
s1.write(90);
delay(1000);
delay(3000);
s1.detach();
}
client.loop();
}
void reconnect() {
// Loop until we're reconnected
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("arduinoClient")) {
if (client.connect(esp_name)) {
Serial.println("connected");
client.subscribe(mqtt_air_topic);
client.subscribe(mqtt_print_topic);
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
@ -146,3 +134,12 @@ void reconnect() {
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
ArduinoOTA.handle();
}