repair script hanging
This commit is contained in:
parent
906340484d
commit
a480476b64
BIN
Deckel.stl
BIN
Deckel.stl
Binary file not shown.
@ -12,3 +12,6 @@
|
|||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
board = esp12e
|
board = esp12e
|
||||||
framework = arduino
|
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 |
@ -2,7 +2,8 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <ESP8266WiFi.h> //ESP library from http://github.com/esp8266/Arduino
|
#include <ESP8266WiFi.h> //ESP library from http://github.com/esp8266/Arduino
|
||||||
#include <PubSubClient.h> // MQTT library from http://github.com/Imroy/pubsubclient
|
#include <PubSubClient.h> // MQTT library from http://github.com/Imroy/pubsubclient
|
||||||
#include "Servo.h"
|
#include <Servo.h>
|
||||||
|
#include <ArduinoOTA.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "user_interface.h"
|
#include "user_interface.h"
|
||||||
@ -11,45 +12,25 @@ extern "C" {
|
|||||||
String esp_id = "duft";
|
String esp_id = "duft";
|
||||||
|
|
||||||
const char *ssid = "iApfel"; // cannot be longer than 32 characters!
|
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* mqtt_server = "192.168.1.5";
|
||||||
|
const char* ota_password = "druffmann77";
|
||||||
|
|
||||||
#define SERV1 12 // Pin connected to the Servomotor
|
#define SERV1 12 // Pin connected to the Servomotor
|
||||||
Servo s1;
|
Servo s1;
|
||||||
|
|
||||||
// Strings zusammen bauen
|
// Strings zusammen bauen
|
||||||
String esp = "esp_wz" + esp_id;
|
String esp = "esp_wz_" + esp_id;
|
||||||
char *esp_name = &esp[0u];
|
char *esp_name = &esp[0u];
|
||||||
|
|
||||||
//String air_topic = "esp" + String(esp_id) + "/room";
|
String print_topic = "airfresh";
|
||||||
//const char* mqtt_air_topic = &air_topic[0u];
|
const char* mqtt_print_topic = &print_topic[0u];
|
||||||
const char* mqtt_air_topic = "airfresh";
|
|
||||||
|
|
||||||
WiFiClient espClient;
|
WiFiClient espClient;
|
||||||
PubSubClient client(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() {
|
void setup_wifi() {
|
||||||
|
delay(10);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
//wifi_set_phy_mode(PHY_MODE_11G);
|
//wifi_set_phy_mode(PHY_MODE_11G);
|
||||||
@ -66,8 +47,8 @@ void setup_wifi() {
|
|||||||
|
|
||||||
// animate LEDs while waiting for connection
|
// animate LEDs while waiting for connection
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
delay(50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
@ -76,30 +57,41 @@ void setup_wifi() {
|
|||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void setup() {
|
||||||
// Check WLan
|
// start the serial connection
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
Serial.begin(115200);
|
||||||
reconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check mqtt messages
|
setup_wifi();
|
||||||
if (!client.connected()) {
|
|
||||||
reconnect();
|
client.setServer(mqtt_server, 1883);
|
||||||
}
|
client.setCallback(callback);
|
||||||
client.loop();
|
|
||||||
|
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) {
|
void callback(char* topic, byte* payload, unsigned int length) {
|
||||||
// Zähler
|
// Zähler
|
||||||
int i = 0;
|
int i = 0;
|
||||||
// Hilfsvariablen für die Convertierung der Nachricht in ein String
|
// Hilfsvariablen für die Convertierung der Nachricht in ein String
|
||||||
char message_buff[100];
|
char message_buff[100];
|
||||||
|
|
||||||
Serial.println("Message arrived: topic: " + String(topic));
|
//Serial.println("Message arrived: topic: " + String(topic));
|
||||||
Serial.println("Length: " + String(length,DEC));
|
//Serial.println("Length: " + String(length,DEC));
|
||||||
|
|
||||||
// Kopieren der Nachricht und erstellen eines Bytes mit abschließender \0
|
// Kopieren der Nachricht und erstellen eines Bytes mit abschließender \0
|
||||||
for(i=0; i<length; i++) {
|
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
|
// Konvertierung der nachricht in ein String
|
||||||
String msgString = String(message_buff);
|
String msgString = String(message_buff);
|
||||||
Serial.println("Payload: " + msgString);
|
//Serial.println("Payload: " + msgString);
|
||||||
|
|
||||||
// if virtual push button was pressed
|
// if virtual push button was pressed
|
||||||
if (msgString.equalsIgnoreCase("1")){
|
if (msgString.equalsIgnoreCase("1")){
|
||||||
Serial.println("Virtual push button");
|
Serial.println("Virtual push button");
|
||||||
s1.attach(SERV1);
|
s1.attach(SERV1);
|
||||||
delay(400);
|
s1.write(60);
|
||||||
s1.write(55);
|
|
||||||
delay(1000);
|
delay(1000);
|
||||||
s1.write(90);
|
s1.write(90);
|
||||||
delay(1000);
|
delay(3000);
|
||||||
s1.detach();
|
s1.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reconnect() {
|
void reconnect() {
|
||||||
// Loop until we're reconnected
|
// Loop until we're reconnected
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
|
||||||
delay(500);
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!client.connected()) {
|
while (!client.connected()) {
|
||||||
Serial.print("Attempting MQTT connection...");
|
Serial.print("Attempting MQTT connection...");
|
||||||
// Attempt to connect
|
// Attempt to connect
|
||||||
if (client.connect("arduinoClient")) {
|
if (client.connect(esp_name)) {
|
||||||
Serial.println("connected");
|
Serial.println("connected");
|
||||||
client.subscribe(mqtt_air_topic);
|
client.subscribe(mqtt_print_topic);
|
||||||
} else {
|
} else {
|
||||||
Serial.print("failed, rc=");
|
Serial.print("failed, rc=");
|
||||||
Serial.print(client.state());
|
Serial.print(client.state());
|
||||||
@ -146,3 +134,12 @@ void reconnect() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if (!client.connected()) {
|
||||||
|
reconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
client.loop();
|
||||||
|
ArduinoOTA.handle();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user