2014-05-14 19:37:04 +02:00
|
|
|
// Do not remove the include below
|
|
|
|
// #include <HardwareSerial.h>
|
|
|
|
|
|
|
|
#include "NetMeterBusMaster2.h"
|
|
|
|
|
|
|
|
#include "cmd.h"
|
|
|
|
#include "test.h"
|
|
|
|
#include "uptime.h"
|
2015-05-08 23:40:36 +02:00
|
|
|
// #include "meterBusServer.h"
|
2014-05-14 19:37:04 +02:00
|
|
|
#include "meterBusMaster.h"
|
|
|
|
#include "overCurrentProt.h"
|
|
|
|
#include <Ethernet.h>
|
2015-05-09 00:08:54 +02:00
|
|
|
#include "MqttClient.h"
|
2015-05-09 23:15:45 +02:00
|
|
|
#include <Streaming.h>
|
2015-05-11 22:36:58 +02:00
|
|
|
#include <Metro.h>
|
|
|
|
#include "config.h"
|
2015-05-13 21:17:11 +02:00
|
|
|
#include "info.h"
|
2015-05-14 10:54:02 +02:00
|
|
|
#include "reset.h"
|
2014-05-14 19:37:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
const uint8_t POWER_LED = 4;
|
|
|
|
const uint8_t ETHERNET_RESET = 14;
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEF };
|
|
|
|
|
|
|
|
static CmdServer cmdServer(2000);
|
|
|
|
static TestCmd testCmd;
|
|
|
|
static Uptime uptime;
|
2015-05-13 21:17:11 +02:00
|
|
|
static InfoCmd infoCmd;
|
2014-05-14 19:37:04 +02:00
|
|
|
|
|
|
|
static MeterBusMaster meterBusMaster;
|
2015-05-09 00:08:54 +02:00
|
|
|
static MqttClient mqttClient(&meterBusMaster);
|
2015-05-08 23:40:36 +02:00
|
|
|
// static MeterBusServer meterBusServer(2001, &meterBusMaster);
|
2014-05-14 19:37:04 +02:00
|
|
|
static OverCurrentProt overCurrentProt;
|
|
|
|
|
2015-05-11 22:36:58 +02:00
|
|
|
Metro wdogTick = Metro(1000);
|
2015-05-13 17:37:05 +02:00
|
|
|
Metro dhcpTick = Metro(60 * 1000);
|
2015-05-11 22:36:58 +02:00
|
|
|
|
2014-05-14 19:37:04 +02:00
|
|
|
|
|
|
|
void setup() {
|
2015-05-11 22:36:58 +02:00
|
|
|
pinMode(POWER_LED, OUTPUT);
|
|
|
|
digitalWrite(POWER_LED, HIGH);
|
|
|
|
|
2014-05-14 19:37:04 +02:00
|
|
|
Serial.begin(115200);
|
|
|
|
delay(100);
|
|
|
|
Serial.println("Starting up ...");
|
|
|
|
|
|
|
|
digitalWrite(POWER_LED, LOW);
|
|
|
|
|
2015-05-11 22:36:58 +02:00
|
|
|
configInit();
|
|
|
|
|
2014-05-14 19:37:04 +02:00
|
|
|
pinMode(ETHERNET_RESET, OUTPUT);
|
|
|
|
digitalWrite(ETHERNET_RESET, LOW);
|
|
|
|
delay(100);
|
|
|
|
digitalWrite(ETHERNET_RESET, HIGH);
|
|
|
|
delay(100);
|
|
|
|
Ethernet.begin(mac);
|
|
|
|
Serial.println("Ethernet started");
|
|
|
|
|
|
|
|
cmdServer.begin();
|
|
|
|
testCmd.registerYourself(&cmdServer);
|
2015-05-13 21:17:11 +02:00
|
|
|
infoCmd.registerYourself(&cmdServer);
|
2014-05-14 19:37:04 +02:00
|
|
|
uptime.begin(&cmdServer);
|
|
|
|
|
|
|
|
overCurrentProt.begin(&cmdServer);
|
|
|
|
meterBusMaster.begin(&cmdServer);
|
2015-05-08 23:40:36 +02:00
|
|
|
// meterBusServer.begin();
|
2015-05-11 22:36:58 +02:00
|
|
|
mqttClient.begin(&cmdServer);
|
2014-05-14 19:37:04 +02:00
|
|
|
|
|
|
|
digitalWrite(POWER_LED, HIGH);
|
2015-05-11 22:36:58 +02:00
|
|
|
|
2014-05-14 19:37:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2015-05-14 10:54:02 +02:00
|
|
|
watchdogReset();
|
2015-05-11 22:36:58 +02:00
|
|
|
|
|
|
|
if (dhcpTick.check() == 1) {
|
|
|
|
byte r = Ethernet.maintain();
|
|
|
|
Serial << "Ethernet.maintain: " << r << endl;
|
2015-05-14 10:54:02 +02:00
|
|
|
if ((r == DHCP_CHECK_REBIND_FAIL) || (r == DHCP_CHECK_RENEW_FAIL)) {
|
|
|
|
resetDevice();
|
|
|
|
}
|
2015-05-11 22:36:58 +02:00
|
|
|
}
|
|
|
|
|
2015-05-09 23:15:45 +02:00
|
|
|
//Serial << "*** 1" << endl;
|
2014-05-14 19:37:04 +02:00
|
|
|
cmdServer.exec();
|
2015-05-09 23:15:45 +02:00
|
|
|
//Serial << "*** 2" << endl;
|
2014-05-14 19:37:04 +02:00
|
|
|
uptime.exec();
|
2015-05-09 23:15:45 +02:00
|
|
|
//Serial << "*** 3" << endl;
|
2014-05-14 19:37:04 +02:00
|
|
|
overCurrentProt.exec();
|
2015-05-09 23:15:45 +02:00
|
|
|
//Serial << "*** 4" << endl;
|
2014-05-14 19:37:04 +02:00
|
|
|
meterBusMaster.exec();
|
2015-05-09 23:15:45 +02:00
|
|
|
//Serial << "*** 5" << endl;
|
2015-05-09 00:08:54 +02:00
|
|
|
mqttClient.exec();
|
2015-05-09 23:15:45 +02:00
|
|
|
//Serial << "*** 6" << endl;
|
2014-05-14 19:37:04 +02:00
|
|
|
}
|