From 8935590aeb989f6a2a8d3f0eb4f314bced8c5aac Mon Sep 17 00:00:00 2001 From: hg Date: Wed, 13 May 2015 22:47:57 +0200 Subject: [PATCH] ready so far --- .settings/org.eclipse.cdt.core.prefs | 6 +++--- WiModbusGateway.cpp | 26 ++++++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/.settings/org.eclipse.cdt.core.prefs b/.settings/org.eclipse.cdt.core.prefs index 56f6456..8419ac1 100644 --- a/.settings/org.eclipse.cdt.core.prefs +++ b/.settings/org.eclipse.cdt.core.prefs @@ -151,10 +151,10 @@ environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.DTS/value=3600 environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.LOCAL/delimiter=\: environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.LOCAL/operation=replace -environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.LOCAL/value=1430902339 +environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.LOCAL/value=1431556581 environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.UTC/delimiter=\: environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.UTC/operation=replace -environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.UTC/value=1430895139 +environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.UTC/value=1431549381 environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.ZONE/delimiter=\: environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.ZONE/operation=replace environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/A.EXTRA.TIME.ZONE/value=3600 @@ -355,7 +355,7 @@ environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/JANTJE. environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/JANTJE.BOARD_NAME/value=Arduino Mega or Mega 2560 environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/JANTJE.COM_PORT/delimiter=\: environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/JANTJE.COM_PORT/operation=replace -environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/JANTJE.COM_PORT/value=/dev/tty.usbmodemfa131 +environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/JANTJE.COM_PORT/value=/dev/tty.usbmodemfd111 environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/JANTJE.COM_PROGMR/delimiter=\: environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/JANTJE.COM_PROGMR/operation=replace environment/project/it.baeyens.arduino.core.toolChain.release.1600398586/JANTJE.COM_PROGMR/value=Default diff --git a/WiModbusGateway.cpp b/WiModbusGateway.cpp index 0aaae02..8dcb172 100644 --- a/WiModbusGateway.cpp +++ b/WiModbusGateway.cpp @@ -11,6 +11,7 @@ #include "PString.h" #include "Streaming.h" #include "PubSubClient.h" +#include @@ -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()); + } + } }