Panel Recovery after a module Reset


This page shows how to easily manage a possible unexpected Wi-Fi module reset and prevent the loss of the panel previously send to the module. In fact, since the panel string is stored in the volatile memory of the WiFi module, after each reset, the module expects to serially receive the string of the panel from the µController.

During a normal power up of your remote system, both µController and wifi module reset: in this case your µController is already programmed to send the initial panel string (with the initial states for any panel object). It is also possible that, at a later time, the µController correctly updates the panel status as result of a user interaction.
But it can also happen that for an unexpected reason only the module reset  (power line fluctuations, low voltage, instable wire connections, electrostatic discharge and so on), if the µController does not send again the panel (with the last updated status) the user will see a blank panel, as shown in figure 1.

Figure 1. Scenario in which your µController does NOT manage the reset message.


To solve this problem just note that, after each reset, the wifi module transmits a reset serial message to your µController, as shown in figure 2.

Figure 2. Serial message from µPanel Module to your µController after a module reset.

This message can be used to monitor if an unexpected module reset occures and eventually retransmit the panel (updated with the current status). In this way, the user will ever see the correct screen, as shown in figure 3. 

Figure 3. Scenario in which your µController manages the reset message and send again the panel. 




Let's consider a simple application in which an Arduino UNO controls two external relays (tha panel layout is shown in the previous figures).
Each time the user presses a switch, the Arduino board will both switch the relay channel and update the led status (used as a feedback).
If a $RES message is received from the wifi module, Arduino transmits again the panel (updated with the current status of the panel objects)

µPanel definition 

The panel definition includes two switch (W1 and W2) and two leds (L1 and L2).

Dg15;/5T*25fb:Arduino Relay;=*16/30{mL1G:0;|*12W1:0;|T:Relay 1;}/{mL2G:0;|*12W2:0;|T:Relay 2;}

Arduino Code

Please note that while loading the sketch on the Arduino UNO, the RxD line (blue wire) has to be disconnected from the WiFi Module

#define RELAY1  8 // first relay on pin 8
#define RELAY2  9 // second relay on pin 8

unsigned char relay1_status = 0;  // OFF
unsigned char relay2_status = 0;  // OFF
String Msg;

void setup() {

  // Initialize Serial Port
  // Let uPanel start 
  // Initialize digital output pin
  digitalWrite(RELAY1, 1);  // pin = high => relay off
  digitalWrite(RELAY2, 1);  // pin = high => relay off
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);

  SendPanel(); // Send The Panel calling a function   

void loop() 
  int c;
  while ((c = > '\n') Msg += (char) c;  // Read incoming chars, if any, until new line
  if (c == '\n')                                       // is the message complete?
    // If switch1 is OFF: Turn OFF LED1 and Relay1 
    if (Msg.equals("#W10")) {digitalWrite(RELAY1,1); Serial.println("#L10"); relay1_status = 0;}  
    // If switch1 is ON: Turn ON LED1 and Relay1 
    else if (Msg.equals("#W11")) {digitalWrite(RELAY1,0); Serial.println("#L11"); relay1_status = 1;}  
    // If switch2 is OFF: Turn OFF LED2 and Relay2 
    else if (Msg.equals("#W20")) {digitalWrite(RELAY2,1); Serial.println("#L20"); relay2_status = 0;}    

    // If switch2 is ON: Turn ON LED2 and Relay2 
    else if (Msg.equals("#W21")) {digitalWrite(RELAY2,0); Serial.println("#L21"); relay2_status = 1;}    

    // WiFi Module unwanted RESET >>>>>>> send panel again
    else if (Msg.equals("$RES")) {SendPanel();}  
    Msg = "";


void SendPanel(void){

  // Discharge old partial messages and send panel
  Serial.println("$P:Dg15;/5T*25fb:Arduino Relay;=*16/30{mL1G:0;|*12W1:0;|T:Relay 1;}/{mL2G:0;|*12W2:0;|T:Relay 2;}");

  // Syncronize all panel's objects status with last valid status
  if (relay1_status == 1){ Serial.println("#W11"); Serial.println("#L11");}
  if (relay2_status == 1){ Serial.println("#W21"); Serial.println("#L21");}