Rest Server stop communicating with Atmega

Hey Yùnners !

Yesterday I have just finished my the last function of my project and mostly because I was so excited rather than to ensure all is perfect, I decided to test all of them.

One of the first thing I made was setting up a Rest Server and it was completely functionnal… until now.
I haven’t touch to the .ino file containing thoses functions. Nothing has change but the wifi mode I turned to STA because it’s a pain in the assassin’s creed to switch from the yùn AP to my local Network to reach the internet. I’ve also change the OS many times (from linino to openwrt to linino trying to use lininoIO then reset to factory then discovering a completly unknow version by trying to unbrick my board) But I am now on the latest version of OpenWRT available to download on Arduino.cc website.

here is my code:

wifi.ino

void WifiSetup(){
  Serial.print(F("Setting WIFI connection : "));
  pinMode(13, OUTPUT);   // sets PIN 13 as an output
  digitalWrite(13, HIGH);  // Sets PIN 13 to HIGH
  Bridge.begin();
  digitalWrite(13, LOW);  // Sets PIN 13 to LOW
  Wifi.listenOnLocalhost();
  Wifi.begin();
  Wifi.println("REST Server is up");
  Serial.println(F("Done"));
}

/****************
 * REST SERVER  */

  void wf_commutation(){
  inter(); // simule une interruption
  Serial.println(F("commutation"));
  Client.println("HTTP/1.1 200 OK\n");    
}

void wf_state(){ // affiche le mode de charge du systeme
  Client.println("HTTP/1.1 200 OK\n"); 
  Client.print(F("Mode: "));
  if(Mode)  Client.println(F("acc"));
  else      Client.println(F("eco")); 
}

void wf_current(){
  Client.println("HTTP/1.1 200 OK\n");
  Client.print(F("current: "));
  Client.println(getIMax());
}

void wf_contact(){ 
  Ack_contact();
}

void wf_error(){
  Client.println("HTTP/1.1 404");
  Serial.println(F("command not found")); 
}

void wf_getd(){
  String d = Client.readStringUntil('\r');
  
  /*Serial.println(d); //DEBUG
  Serial.println(d.length());
  char temp[16];
  d.getBytes(temp,sizeof(temp));
  int lop;

  for(lop=0;lop<16;lop++){

    Serial.print(lop);
    Serial.print(" ");
    Serial.println(temp[lop],HEX);
  }*/
  
  if(d == "state"){
    wf_state();
  }
  else if(d == "current"){
    wf_current();
  }
  else{
    //Serial.println(F("error wf_getd"));
    wf_error();
  }
}
void wf_process(){
  //Serial.println("Processing Rest server");
  Client = Wifi.accept();
  while(Client.available()){
    Serial.println("request received");
    if (Client.readStringUntil('/') == "mode"){
      wf_switch();
    }
    else
      Serial.println(F("command not found (process)"));//wf_error();
  }
  Client.stop();
}


void wf_switch(){
  String command = Client.readString();//Until('/');

  char temp[30];
  command.getBytes(temp,sizeof(temp));
  int lop;

  for(lop=0;lop<30;lop++){

    Serial.print(lop);
    Serial.print(" ");
    Serial.println(temp[lop],HEX);
  }
  
  Serial.print(F("Commande : "));
  //Serial.print(command);
  if (command == "commutation\r\n"){
    wf_commutation();
  }
  else if (command == "get"){
    wf_getd();
  }
  else {
    wf_error();
    Serial.println(F("error wf_switch"));
  }
}

main.ino (shortened)

#include <Wire.h>
#include <Bridge.h>
#include <BridgeServer.h>
  BridgeServer Wifi;
#include <BridgeClient.h>
  BridgeClient Client;
#include <Process.h>

void setup(){
  Serial.begin(115200);
  while(!Serial); // waits for Serial Monitor to open
  WifiSetup();
}

void loop(){
  wf_process();
}

The code enter the function wf_process() but Client.available() never returns a true value because “received request” will never be printed.

Can you help me finding out what I’m doing wong, what else changed or whatever that can help me?
Thank you very much to all of you and happy 2018 !

Ok guys, so I got the proof posting a complete code is [u]important[/u].

without the complete code you couldn't got it.

I found out that putting the yun in sleep mode mess up the serial link. Because the rest server is on the Atheros side, we communicate the '/arduino/…' strings to the Atmega through the Bridge that use the Serial link.

So here an option to resolve this issue: first, when going to sleep, don't forget to brush you teeth, but the most important, end the Serial link and disable the USB connection (otherwise, the serial monitor dies in pain*) and begin the serial link and usb when the Atmega wakes up. On my side, I'll stop using the sleep because it isn't pertinent enough for my solution and because the Atheros chip is responsible for the most of the board power consumption, asleeping the Atmega doesn't worth that much.