Removed some code written to recover from a strange connection error because it didn't work as expected. The temporary fix I did is to make a preventive MCU reset every 5 hours or when the connection error appears, until I can find the cause of it.
This commit is contained in:
		
							parent
							
								
									11ed8dfb37
								
							
						
					
					
						commit
						ad70fdccea
					
				| @ -22,6 +22,7 @@ | ||||
| #define CHAN 108   //0-125
 | ||||
| #define RECV_CHECK 5000 //We test every 5s if we received something
 | ||||
| #define WIFI_CHECK_TIMEOUT 20000 | ||||
| #define PREVENTIVE_RESET_DELAY 18000000 //Every 5 hours
 | ||||
| 
 | ||||
| uint8_t payload[32] = {0}; | ||||
| DataPacket dp; | ||||
| @ -39,11 +40,13 @@ HttpClient DBHost(DB_SERVER, PATH); | ||||
| Dictionary<DictionaryHelper::StringEntity> weatherStationPostData, mailboxPostData; | ||||
| 
 | ||||
| const uint8_t ADDR[] = "WEST1", ADDR2[] = "ABCDE"; | ||||
| uint64_t timeStamp(0), irqSaver(0); | ||||
| uint32_t timeStamp(0), irqSaver(0), resetTimeStamp(0); | ||||
| uint32_t freeMem(0); | ||||
| uint16_t biggestContigMemBlock(0); | ||||
| uint8_t frag(0); | ||||
| int insertIntoDBError(0); | ||||
| volatile boolean IRQFlag(false); | ||||
| boolean waitingForResetSignal(false), resetNow(false); | ||||
| 
 | ||||
| IRAM_ATTR void NRFIRQsHandler(void *p) | ||||
| { | ||||
| @ -158,19 +161,21 @@ void loop() | ||||
|           { | ||||
|             memcpy(&wsdp, payload, sizeof(wsdp)); | ||||
|             debugStruct(&wsdp); | ||||
|             insertIntoDB(&wsdp); | ||||
|             insertIntoDBError = insertIntoDB(&wsdp); | ||||
|           } | ||||
|             break; | ||||
|           case CONNECTED_MAILBOX: | ||||
|           { | ||||
|             memcpy(&mdp, payload, sizeof(mdp)); | ||||
|             debugStruct(&mdp); | ||||
|             insertIntoDB(&mdp); | ||||
|             insertIntoDBError = insertIntoDB(&mdp); | ||||
|           } | ||||
|             break; | ||||
|           default: | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(waitingForResetSignal)resetNow = true; | ||||
|       } | ||||
|     } | ||||
|      | ||||
| @ -201,19 +206,21 @@ void loop() | ||||
|           { | ||||
|             memcpy(&wsdp, payload, sizeof(wsdp)); | ||||
|             debugStruct(&wsdp); | ||||
|             insertIntoDB(&wsdp); | ||||
|             insertIntoDBError = insertIntoDB(&wsdp); | ||||
|           } | ||||
|             break; | ||||
|           case CONNECTED_MAILBOX: | ||||
|           { | ||||
|             memcpy(&mdp, payload, sizeof(mdp)); | ||||
|             debugStruct(&mdp); | ||||
|             insertIntoDB(&mdp); | ||||
|             insertIntoDBError = insertIntoDB(&mdp); | ||||
|           } | ||||
|             break; | ||||
|           default: | ||||
|             break; | ||||
|         } | ||||
| 
 | ||||
|         if(waitingForResetSignal)resetNow = true; | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
| @ -254,6 +261,19 @@ void loop() | ||||
|     } | ||||
|     timeStamp = millis(); | ||||
|   } | ||||
| 
 | ||||
|   //Here we handle the reset
 | ||||
|   if(millis() - resetTimeStamp > PREVENTIVE_RESET_DELAY) | ||||
|   { | ||||
|     Serial.println("Waiting next payload before resetting MCU :( !"); | ||||
|     waitingForResetSignal = true; | ||||
|     resetTimeStamp = millis(); | ||||
|   } | ||||
| 
 | ||||
|   if((waitingForResetSignal && resetNow) || insertIntoDBError == -125) | ||||
|   { | ||||
|     ESP.reset(); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
| @ -271,7 +291,7 @@ void lostConnectionFunc(const WiFiEventStationModeDisconnected &event) | ||||
|   Serial.println("Lost connection, will try to reconnect ..."); | ||||
| } | ||||
| 
 | ||||
| void insertIntoDB(WeatherStationDataPacket *p) | ||||
| int insertIntoDB(WeatherStationDataPacket *p) | ||||
| { | ||||
|   char buffer[100] = ""; | ||||
|   int result(0); | ||||
| @ -309,27 +329,10 @@ void insertIntoDB(WeatherStationDataPacket *p) | ||||
|    else | ||||
|    { | ||||
|     Serial.printf("Failed to post data : error(%d)\n", result); | ||||
|     if(result == -125) | ||||
|     { | ||||
|       WiFi.disconnect(); | ||||
|       WiFi.begin(SSID, PWD); | ||||
| 
 | ||||
|       while(!WiFi.isConnected()) | ||||
|       { | ||||
|         Serial.println("Reconnecting !"); | ||||
|       } | ||||
|       if((result = DBHost.sendHttpQuery(HttpClient::HttpRequestMethod::POST, NULL, &weatherStationPostData)) == 0) | ||||
|       { | ||||
|         HttpClient::HTTP_CODE response = DBHost.isReplyAvailable(2000); | ||||
|         Serial.printf("Second send got response code : %u\n", response); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         Serial.printf("Second send failed to post data : error(%d)\n", result); | ||||
|       } | ||||
|     } | ||||
|    } | ||||
|    DBHost.stop(); | ||||
| 
 | ||||
|    return result; | ||||
| } | ||||
| 
 | ||||
| void debugStruct(WeatherStationDataPacket *p) | ||||
| @ -367,7 +370,7 @@ void debugStruct(WeatherStationDataPacket *p) | ||||
|   Serial.println(" *C"); | ||||
| } | ||||
| 
 | ||||
| void insertIntoDB(MailboxDataPacket *p) | ||||
| int insertIntoDB(MailboxDataPacket *p) | ||||
| { | ||||
|   char buffer[100] = ""; | ||||
|   int result(0); | ||||
| @ -404,6 +407,8 @@ void insertIntoDB(MailboxDataPacket *p) | ||||
|     Serial.printf("Failed to post data : error(%d)\n", result); | ||||
|    } | ||||
|    DBHost.stop(); | ||||
| 
 | ||||
|    return result; | ||||
| } | ||||
| 
 | ||||
| void debugStruct(MailboxDataPacket *p) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user