waterishosgen2_public/waterishos-gen2-mesh/waterishos-gen2-mesh.ino

57 lines
1.7 KiB
Arduino
Raw Normal View History

2019-08-21 13:17:09 +00:00
#include <BearSSLHelpers.h>
#include <CertStoreBearSSL.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiClientSecureAxTLS.h>
#include <WiFiClientSecureBearSSL.h>
#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiServerSecureAxTLS.h>
#include <WiFiServerSecureBearSSL.h>
#include <WiFiUdp.h>
#include <ESP8266WiFiMesh.h>
#include <NetworkInfo.h>
#include <TransmissionResult.h>
#include <TypeConversionFunctions.h>
2019-08-21 12:31:52 +00:00
#include "settings.h"
#include <ESP8266MQTTMesh.h>
#include <FS.h>
2019-08-21 12:51:02 +00:00
// |----------------------------------|
// | SIWAT INC |
// |----------------------------------|
2019-08-21 12:31:52 +00:00
String ID = String(ESP.getChipId());
unsigned long previousMillis = 0;
const long interval = 5000;
int cnt = 0;
2019-08-21 13:17:09 +00:00
ESP8266MQTTMesh mesh = ESP8266MQTTMesh::Builder(networks, mqtt_server, mqtt_port).setMqttAuth(mqtt_user, mqtt_password).setVersion(FIRMWARE_VER, FIRMWARE_ID).setMeshPassword(mesh_password).setMeshSSID(mesh_ssid).build();
2019-08-21 12:53:07 +00:00
void callback(const char *topic, const char *msg);
2019-08-21 12:06:21 +00:00
void setup() {
2019-08-21 12:31:52 +00:00
Serial.begin(115200);
2019-08-21 12:51:02 +00:00
delay(1000);
2019-08-21 12:31:52 +00:00
mesh.setCallback(callback);
mesh.begin();
2019-08-21 12:06:21 +00:00
}
2019-08-21 12:31:52 +00:00
2019-08-21 12:06:21 +00:00
void loop() {
2019-08-21 12:51:02 +00:00
if (! mesh.connected())return;
2019-08-21 12:31:52 +00:00
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
2019-08-21 12:53:07 +00:00
mesh.publish("/test","test");
2019-08-21 12:31:52 +00:00
previousMillis = currentMillis;
cnt++;
}
}
void callback(const char *topic, const char *msg) {
Serial.print(topic);
Serial.print(msg);
2019-08-21 12:06:21 +00:00
}