I’m currently developing a project using wio terminal. It holds mostly it holds a BLE server , a wifi web server, and i m using the build in LCD also.
BLE gets datas from sensors, web serser handling http get requests, LCD prints some messages( about 1 message / 2 seconds, 20 bytes per message, low loading!)
most of the time when wio terminal power up or resets , lcd starts success, Wifi connects success, web server starts success;
but the problem is afte some tens of successful handling http get requests from a client, the web server die itself , and at the same time, actually all the code inside the Loop() is not runing any more , only the BLE notifification reception and the corresponding notify call back remain runing .
struggling this issue for days already! all library is updated as requested, any idea ?
void setup() {
tft.begin();
tft.setRotation(3);
tft.fillRect(0,0,320,20,headLineColor);
tft.fillRect(0,20,320,40,backColor);
tft.fillRect(0,60,320,180,backColor);
tft.setFreeFont(&LCD_FONT);
tft.setTextColor(TFT_WHITE);
tft.setCursor(5,15);
tft.println("*********** Gateway Console ***********");
//lcd_log_status();
Serial.begin(115200);
WiFi.mode(WIFI_STA);
Serial.println(WiFi.macAddress());
sprintf(buf, "->Gateway MAC: %s", WiFi.macAddress().c_str());
lcd_log_line(buf);
delay(10000);
WiFi.begin(ssid, password);
// Configures static IP address
if (!WiFi.config(local_IP, gateway, subnet /*, primaryDNS, secondaryDNS*/)) {
Serial.println("STA Failed to configure");
lcd_log_line((char *)"->STA Failed to configure");
}
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
lcd_log_line(itoa((int)WiFi.status(), buf, 10));
pinMode(RTL8720D_CHIP_PU, OUTPUT);
digitalWrite(RTL8720D_CHIP_PU, LOW);
delay(500);
digitalWrite(RTL8720D_CHIP_PU, HIGH);
delay(500);
tcpip_adapter_init();
WiFi.begin(ssid, password);
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("Local IP address: ");
Serial.println(WiFi.localIP());
sprintf(buf, "->Connected to: %s", ssid);
lcd_log_line(buf);
sprintf(buf, "->Local IP Add: %s", WiFi.localIP().toString().c_str());
lcd_log_line(buf);
server.on("/", handleRoot);
server.on("/Info", handleInfo);
server.on("/Analog/Leakage,HeartBeat", handleStatus);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started!");
lcd_log_line((char *)"->HTTP server started!");
// BLE
Serial.println("Starting Arduino BLE Client application...");
lcd_log_line((char *)"->Starting BLE Client");
BLEDevice::init("");
// Retrieve a Scanner and set the callback we want to use to be informed when we
// have detected a new device. Specify that we want active scanning and start the
// scan to run for 5 seconds.
BLEScan* pBLEScan = BLEDevice::getScan();
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setInterval(1349);
pBLEScan->setWindow(449);
pBLEScan->setActiveScan(true);
pBLEScan->start(8, false);
previousMillis = millis();
} // End of setup.
// This is the Arduino main loop function.
void loop() {
yield();
server.handleClient();
// to update heartBeat Pool
if (millis() - previousMillis >= 10000){
String hbmessage ="";
String leakmessage ="";
for (byte i=0;i<boardCnt;i++){
// yield();
if ( millis()-heartBeatTime[i] >= heartBeatSpec){ heartBeat[i] = boardPool[i]; }
if (heartBeat[i]!=0){hbmessage+=String(heartBeat[i]);}
if (leakPool[i]!=0){leakmessage+=String(leakPool[i]);}
}
//Serial.print("Zone HeartBeat status: ");Serial.println(hbmessage.toInt());
//Serial.print("Zone Leakage status: ");Serial.println(leakmessage.toInt());
//lcd_log_status();
previousMillis = millis();
}
// If the flag "doConnect" is true then we have scanned for and found the desired
// BLE Server with which we wish to connect. Now we connect to it. Once we are
// connected we set the connected flag to be true.
if (doConnect == true) {
if (connectToServer()) {
Serial.println("We are now connected to the BLE Server.");
lcd_log_line((char *)"->connected to BLE Server!");
} else {
Serial.println("We have failed to connect to the server; there is nothin more we will do.");
lcd_log_line((char *)"->BLE Connection Fail!");
}
doConnect = false;
}
if (connected){
}
else if (!connected) {
NVIC_SystemReset();
//BLEDevice::getScan()->start(5,false); // this is just eample to start scan after disconnect, most likely there is better way to do it in arduino
//Serial.println("BLE: now try to connect again!");
}
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
lcd_log_line(itoa((int)WiFi.status(), buf, 10));
pinMode(RTL8720D_CHIP_PU, OUTPUT);
digitalWrite(RTL8720D_CHIP_PU, LOW);
delay(500);
digitalWrite(RTL8720D_CHIP_PU, HIGH);
delay(500);
tcpip_adapter_init();
WiFi.begin(ssid, password);
}
} // End of loop