Update WaterishOS-core2.0.ino

This commit is contained in:
Siwat Sirichai 2019-08-12 16:09:36 +07:00
parent 5c333d3b58
commit 9c28acfd4d
1 changed files with 13 additions and 7 deletions

View File

@ -82,23 +82,27 @@ void setup() {
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password); WiFi.begin(ssid, password);
int connectionattempt = 0; int connectionattempt = 0;
while (WiFi.status() != WL_CONNECTED) while (WiFi.status() != WL_CONNECTED && online)
{ {
//wait for it ... (Wait for Wifi Connection) //wait for it ... (Wait for Wifi Connection)
writelcd("WiFi Connecting"," Attempt "+String(connectionattempt)); writelcd("WiFi Connecting"," Attempt "+String(connectionattempt));
connectionattempt++; connectionattempt++;
delay(500); delay(500);
if (connectionattempt >= 20) { if (connectionattempt >= 20) {
writelcd(" Cannot Connect"," Going Offline!");
delay(3000);
online = false; online = false;
break;
} }
} }
writelcd("Boot Sequence P3"," Loading Kernel");
attachInterrupt(digitalPinToInterrupt(1), readA, FALLING); attachInterrupt(digitalPinToInterrupt(1), readA, FALLING);
attachInterrupt(digitalPinToInterrupt(3), readB, FALLING); attachInterrupt(digitalPinToInterrupt(3), readB, FALLING);
pinMode(1, FUNCTION_3); pinMode(1, FUNCTION_3);
pinMode(3, FUNCTION_3); pinMode(3, FUNCTION_3);
pinMode(1, INPUT); pinMode(1, INPUT);
pinMode(3, INPUT); pinMode(3, INPUT);
delay(1000);
writelcd("Boot Sequence P3","Waking Processor");
mcp.begin(); mcp.begin();
mcp.setupInterrupts(true, false, LOW); mcp.setupInterrupts(true, false, LOW);
for (int i = 0; i <= 15; i++) for (int i = 0; i <= 15; i++)
@ -106,15 +110,17 @@ void setup() {
mcp.pinMode(i, INPUT); mcp.pinMode(i, INPUT);
mcp.setupInterruptPin(i, RISING); mcp.setupInterruptPin(i, RISING);
} }
delay(1000);
writelcd("Boot Sequence P3"," Success!");
datacollector.onRun(collectdata); datacollector.onRun(collectdata);
datacollector.setInterval(1000); datacollector.setInterval(1000);
mqttupdater.onRun(updatemqtt); if(online)mqttupdater.onRun(updatemqtt);
mqttupdater.setInterval(1000); if(online)mqttupdater.setInterval(1000);
threadControl.add(&datacollector); threadControl.add(&datacollector);
threadControl.add(&mqttupdater); if(online)threadControl.add(&mqttupdater);
} }
void loop() { void loop() {
client.loop(); if(online)client.loop();
threadControl.run(); threadControl.run();
} }