From 5c7d1b691a3a74d345b14356e3469b4946fee371 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 19:31:52 +0700 Subject: [PATCH 1/5] code edit --- waterishos-gen2-mesh/waterishos-gen2-mesh.ino | 71 ++++++++++++++++++- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/waterishos-gen2-mesh/waterishos-gen2-mesh.ino b/waterishos-gen2-mesh/waterishos-gen2-mesh.ino index 95c2b6e..4911fd4 100644 --- a/waterishos-gen2-mesh/waterishos-gen2-mesh.ino +++ b/waterishos-gen2-mesh/waterishos-gen2-mesh.ino @@ -1,9 +1,76 @@ +#include "settings.h" +#include +#include + + +#define FIRMWARE_ID 0x1337 +#define FIRMWARE_VER "0.1" +wifi_conn networks[] = {WIFI_CONN("ssid 1", NETWORK_PASSWORD, NULL, 0),WIFI_CONN("ssid 2", NETWORK_PASSWORD, NULL, 0),NULL,}; +const char* mesh_password = MESH_PASSWORD; +const char* mqtt_server = MQTT_SERVER; +const int mqtt_port = MQTT_PORT; +#if ASYNC_TCP_SSL_ENABLED +const uint8_t *mqtt_fingerprint = MQTT_FINGERPRINT; +bool mqtt_secure = MQTT_SECURE; + #if MESH_SECURE + #include "ssl_cert.h" + #endif +#endif + +#ifdef ESP32 +String ID = String((unsigned long)ESP.getEfuseMac()); +#else +String ID = String(ESP.getChipId()); +#endif + + + + +unsigned long previousMillis = 0; +const long interval = 5000; +int cnt = 0; + +// Note: All of the '.set' options below are optional. The default values can be +// found in ESP8266MQTTMeshBuilder.h +ESP8266MQTTMesh mesh = ESP8266MQTTMesh::Builder(networks, mqtt_server, mqtt_port).setVersion(FIRMWARE_VER, FIRMWARE_ID).setMeshPassword(mesh_password).build(); + +void callback(const char *topic, const char *msg); + + + void setup() { - // put your setup code here, to run once: + + Serial.begin(115200); + delay(1000); //This is only here to make it easier to catch the startup messages. It isn't required + mesh.setCallback(callback); + mesh.begin(); } + void loop() { - // put your main code here, to run repeatedly: + + + if (! mesh.connected()) + return; + + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + + String cntStr = String(cnt); + String msg = "hello from " + ID + " cnt: " + cntStr; + mesh.publish(ID.c_str(), msg.c_str()); + previousMillis = currentMillis; + cnt++; + + } } + + + +void callback(const char *topic, const char *msg) { + Serial.print(topic); + Serial.print(msg); +} From d68779759be7c84a1fd973975c4019f71d688118 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 19:38:36 +0700 Subject: [PATCH 2/5] Delete Rogue Example File --- .../ESP8266MeshHelloWorld.ino | 89 ------------------- 1 file changed, 89 deletions(-) delete mode 100644 waterishos-gen2-mesh/ESP8266MeshHelloWorld.ino diff --git a/waterishos-gen2-mesh/ESP8266MeshHelloWorld.ino b/waterishos-gen2-mesh/ESP8266MeshHelloWorld.ino deleted file mode 100644 index a77a141..0000000 --- a/waterishos-gen2-mesh/ESP8266MeshHelloWorld.ino +++ /dev/null @@ -1,89 +0,0 @@ -#include "credentials.h" -#include -#include - - -#ifndef LED_PIN - #define LED_PIN LED_BUILTIN -#endif - - -#define FIRMWARE_ID 0x1337 -#define FIRMWARE_VER "0.1" -wifi_conn networks[] = {WIFI_CONN("ssid 1", NETWORK_PASSWORD, NULL, 0),WIFI_CONN("ssid 2", NETWORK_PASSWORD, NULL, 0),NULL,}; -const char* mesh_password = MESH_PASSWORD; -const char* mqtt_server = MQTT_SERVER; -const int mqtt_port = MQTT_PORT; -#if ASYNC_TCP_SSL_ENABLED -const uint8_t *mqtt_fingerprint = MQTT_FINGERPRINT; -bool mqtt_secure = MQTT_SECURE; - #if MESH_SECURE - #include "ssl_cert.h" - #endif -#endif - -#ifdef ESP32 -String ID = String((unsigned long)ESP.getEfuseMac()); -#else -String ID = String(ESP.getChipId()); -#endif - - - - -unsigned long previousMillis = 0; -const long interval = 5000; -int cnt = 0; - -// Note: All of the '.set' options below are optional. The default values can be -// found in ESP8266MQTTMeshBuilder.h -ESP8266MQTTMesh mesh = ESP8266MQTTMesh::Builder(networks, mqtt_server, mqtt_port).setVersion(FIRMWARE_VER, FIRMWARE_ID).setMeshPassword(mesh_password).build(); - -void callback(const char *topic, const char *msg); - - - -void setup() { - - Serial.begin(115200); - delay(1000); //This is only here to make it easier to catch the startup messages. It isn't required - mesh.setCallback(callback); - mesh.begin(); - pinMode(LED_PIN, OUTPUT); - -} - - -void loop() { - - - if (! mesh.connected()) - return; - - unsigned long currentMillis = millis(); - - if (currentMillis - previousMillis >= interval) { - - String cntStr = String(cnt); - String msg = "hello from " + ID + " cnt: " + cntStr; - mesh.publish(ID.c_str(), msg.c_str()); - previousMillis = currentMillis; - cnt++; - - } - -} - - - -void callback(const char *topic, const char *msg) { - - - if (0 == strcmp(topic, (const char*) ID.c_str())) { - if(String(msg) == "0") { - digitalWrite(LED_PIN, HIGH); - }else{ - digitalWrite(LED_PIN, LOW); - } - } -} From 0ea69e53eba9516d0073b9400c0bc6f08fa7c6c8 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 19:38:47 +0700 Subject: [PATCH 3/5] edit main mesh source code --- waterishos-gen2-mesh/waterishos-gen2-mesh.ino | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/waterishos-gen2-mesh/waterishos-gen2-mesh.ino b/waterishos-gen2-mesh/waterishos-gen2-mesh.ino index 4911fd4..073d2ea 100644 --- a/waterishos-gen2-mesh/waterishos-gen2-mesh.ino +++ b/waterishos-gen2-mesh/waterishos-gen2-mesh.ino @@ -9,19 +9,7 @@ wifi_conn networks[] = {WIFI_CONN("ssid 1", NETWORK_PASSWORD, NULL, 0), const char* mesh_password = MESH_PASSWORD; const char* mqtt_server = MQTT_SERVER; const int mqtt_port = MQTT_PORT; -#if ASYNC_TCP_SSL_ENABLED -const uint8_t *mqtt_fingerprint = MQTT_FINGERPRINT; -bool mqtt_secure = MQTT_SECURE; - #if MESH_SECURE - #include "ssl_cert.h" - #endif -#endif - -#ifdef ESP32 -String ID = String((unsigned long)ESP.getEfuseMac()); -#else String ID = String(ESP.getChipId()); -#endif From 15d0655fdd1c28d2977d5bec11bbe6b8f84f2e26 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 19:39:58 +0700 Subject: [PATCH 4/5] update code --- waterishos-gen2-mesh/waterishos-gen2-mesh.ino | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/waterishos-gen2-mesh/waterishos-gen2-mesh.ino b/waterishos-gen2-mesh/waterishos-gen2-mesh.ino index 073d2ea..c122ded 100644 --- a/waterishos-gen2-mesh/waterishos-gen2-mesh.ino +++ b/waterishos-gen2-mesh/waterishos-gen2-mesh.ino @@ -5,10 +5,8 @@ #define FIRMWARE_ID 0x1337 #define FIRMWARE_VER "0.1" -wifi_conn networks[] = {WIFI_CONN("ssid 1", NETWORK_PASSWORD, NULL, 0),WIFI_CONN("ssid 2", NETWORK_PASSWORD, NULL, 0),NULL,}; -const char* mesh_password = MESH_PASSWORD; -const char* mqtt_server = MQTT_SERVER; -const int mqtt_port = MQTT_PORT; +wifi_conn networks[] = {WIFI_CONN("ssid 1", "Password", NULL, 0),WIFI_CONN("ssid 2", "Another Password", NULL, 0),NULL,}; + String ID = String(ESP.getChipId()); From 9b246310ded3ab8bbf5bcaa0f5bd4ce69703ef1c Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Wed, 21 Aug 2019 12:41:21 +0000 Subject: [PATCH 5/5] Creating new file readme.md --- readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..e69de29