Project

General

Profile

Race condition between serial and ethernet comms?

Added by zoic21 over 6 years ago

Hi,

I have some trouble with serial, ethercard and RF12B.

Context : this is master code, master received message from slave jeenode. Each message contain a value from like this :

struct message {
  byte dest;
  byte expe;
  byte port;
  byte type;
  byte event;
  byte mode;
  byte value;
  byte value1;
  byte value2;
  byte value3;
} 

Then master prepare post request for php server like this : api=aaaaaaaaaaaaaaaaaa&type=jeenode&n=nn&p=pp&&t=tt&v=vv then server deals the request.

Another mode is master received request from server like this 192.168.0.11?n=nn&&p=pp&t=tt&m=mm&v=vv&=v1=v1&v2=v2&v3=v3. Server send request by rf12 to jeenode nn, jeenode send his reply and master send it to server.

Problem :
- In debug mode master node always reboot I think is due to this condition “if (pos) {” which seem always true because if I remove it or this line :

if(atoi(port) == 0){              
            if(type[0] == 'r'){
#if DEBUG          
              Serial.println("Ask for free ram");
              serialFlush();
#endif 
              ether.httpServerReply(page(intToChar(freeRam())));
            }
            if(type[0] == 'u'){
#if DEBUG          
              Serial.println("Ask for uptime");
              serialFlush();
#endif 
              ether.httpServerReply(pageUptime(millis()));

Master starts normally.

  • Then if master start normally everything seems to work correctly except master never call server on event in serial console I can see see “Sending event to server…End” so master call function sendToJeedom() and this function seem to work but I haven’t any access on my http server….

  • The last but not least php server didn’t received all message. Jeenode slave send every 5 min 3 or 4 measure to master most of the time server received all value but sometime one value is missing, I can’t understand why ?

Thank you in advance for your response