ready so far
This commit is contained in:
@ -11,6 +11,7 @@
|
||||
#include "PString.h"
|
||||
#include "Streaming.h"
|
||||
#include "PubSubClient.h"
|
||||
#include <avr/wdt.h>
|
||||
|
||||
|
||||
|
||||
@ -22,7 +23,8 @@ LiquidCrystal lcd = LiquidCrystal(A0, A1, A2, A3, A4, A5);
|
||||
// WiFiUDP udpSock;
|
||||
WiFiClient wifiClient;
|
||||
//byte server[] = { 192, 168, 87, 100 };
|
||||
byte server[] = { 172, 16, 2, 16 };
|
||||
//byte server[] = { 172, 16, 2, 16 };
|
||||
char server[] = "mqttbroker";
|
||||
PubSubClient client(server, 1883, callback, wifiClient);
|
||||
uint8_t disconnectState = 0;
|
||||
uint32_t disconnectTime = 0;
|
||||
@ -33,7 +35,7 @@ uint32_t disconnectTime = 0;
|
||||
char ssid[] = "MessWLAN";
|
||||
char pass[] = "UNVmpwbr6heQnMQ7ykXT";
|
||||
|
||||
Metro tick = Metro(10000);
|
||||
Metro minute = Metro(60000);
|
||||
Metro second = Metro(1000);
|
||||
uint32_t uptime;
|
||||
|
||||
@ -130,6 +132,8 @@ void setup() {
|
||||
// Mb.R[123] = 0xdead; // magic
|
||||
// Mb.R[124] = 0xbeef;
|
||||
|
||||
wdt_enable(WDTO_8S);
|
||||
|
||||
|
||||
// modbusAppBegin(&Mb);
|
||||
modbusAppBegin();
|
||||
@ -177,6 +181,8 @@ void updateDisplay() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
wdt_reset();
|
||||
|
||||
updateDisplay();
|
||||
|
||||
modbusAppExec();
|
||||
@ -221,9 +227,9 @@ void loop() {
|
||||
|
||||
|
||||
|
||||
if (second.check() == 1) {
|
||||
uptime++;
|
||||
|
||||
|
||||
if (minute.check() == 1) {
|
||||
char strbuf[256];
|
||||
memset(strbuf, sizeof(strbuf), 0);
|
||||
PString buf = PString(strbuf, sizeof(strbuf));
|
||||
@ -239,14 +245,22 @@ void loop() {
|
||||
"}" <<
|
||||
"}" << endl;
|
||||
if (disconnectState == 0) {
|
||||
client.publish("IoT", strbuf);
|
||||
client.publish("IoT/WiFiPowerMeter/Measurement", strbuf);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (tick.check() == 1) {
|
||||
if (second.check() == 1) {
|
||||
uptime++;
|
||||
|
||||
Serial.println("tick");
|
||||
|
||||
String msg = String("{ \"metadata\": { \"device\": \"WiFiPowerMeter\" }, \"data\": { \"uptime\": ") + uptime + String("}}");
|
||||
if (disconnectState == 0) {
|
||||
client.publish("IoT/WiFiPowerMeter/Heartbeat", (char*)msg.c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user