configuration partly done
This commit is contained in:
@ -12,6 +12,8 @@
|
||||
#include <Ethernet.h>
|
||||
#include "MqttClient.h"
|
||||
#include <Streaming.h>
|
||||
#include <Metro.h>
|
||||
#include "config.h"
|
||||
|
||||
|
||||
const uint8_t POWER_LED = 4;
|
||||
@ -29,15 +31,37 @@ static MqttClient mqttClient(&meterBusMaster);
|
||||
// static MeterBusServer meterBusServer(2001, &meterBusMaster);
|
||||
static OverCurrentProt overCurrentProt;
|
||||
|
||||
Metro wdogTick = Metro(1000);
|
||||
Metro dhcpTick = Metro(5* 60 * 1000);
|
||||
|
||||
extern "C" {
|
||||
void startup_early_hook( ) __attribute__ ((weak));
|
||||
void startup_early_hook() {
|
||||
// enable watchdog
|
||||
WDOG_UNLOCK = WDOG_UNLOCK_SEQ1;
|
||||
WDOG_UNLOCK = WDOG_UNLOCK_SEQ2;
|
||||
|
||||
// one minute
|
||||
WDOG_TOVALL = 0xea60;
|
||||
WDOG_TOVALH = 0;
|
||||
WDOG_PRESC = 0;
|
||||
|
||||
WDOG_STCTRLH = WDOG_STCTRLH_WDOGEN | WDOG_STCTRLH_ALLOWUPDATE | WDOG_STCTRLH_STOPEN | WDOG_STCTRLH_WAITEN;
|
||||
}
|
||||
} // extern "C"
|
||||
|
||||
void setup() {
|
||||
pinMode(POWER_LED, OUTPUT);
|
||||
digitalWrite(POWER_LED, HIGH);
|
||||
|
||||
Serial.begin(115200);
|
||||
delay(100);
|
||||
Serial.println("Starting up ...");
|
||||
|
||||
pinMode(POWER_LED, OUTPUT);
|
||||
digitalWrite(POWER_LED, LOW);
|
||||
|
||||
configInit();
|
||||
|
||||
pinMode(ETHERNET_RESET, OUTPUT);
|
||||
digitalWrite(ETHERNET_RESET, LOW);
|
||||
delay(100);
|
||||
@ -53,12 +77,33 @@ void setup() {
|
||||
overCurrentProt.begin(&cmdServer);
|
||||
meterBusMaster.begin(&cmdServer);
|
||||
// meterBusServer.begin();
|
||||
mqttClient.begin();
|
||||
mqttClient.begin(&cmdServer);
|
||||
|
||||
digitalWrite(POWER_LED, HIGH);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// watchdog refresh
|
||||
cli();
|
||||
WDOG_REFRESH = 0xa602;
|
||||
WDOG_REFRESH = 0xb480;
|
||||
sei();
|
||||
|
||||
|
||||
if (wdogTick.check() == 1) {
|
||||
uint16_t h = WDOG_TMROUTH;
|
||||
uint16_t l = WDOG_TMROUTL;
|
||||
uint16_t c = WDOG_RSTCNT;
|
||||
|
||||
Serial << "WDog, h: " << _HEX(h) << ", l: " << _HEX(l) << ", c: " << _HEX(c) << endl;
|
||||
}
|
||||
|
||||
if (dhcpTick.check() == 1) {
|
||||
byte r = Ethernet.maintain();
|
||||
Serial << "Ethernet.maintain: " << r << endl;
|
||||
}
|
||||
|
||||
//Serial << "*** 1" << endl;
|
||||
cmdServer.exec();
|
||||
//Serial << "*** 2" << endl;
|
||||
|
Reference in New Issue
Block a user