[SOLVED] Difference between YunClient.h and Wifi from UnoWifi ?

Hello Everyone !

I’m on a project I’ve started on Arduino Uno Wifi I’m moving on Arduino YÙN Mini and It’s almost done except one thing: The wifi.

I figured out that it was working around the same way on the two board except on Yùn, you need to include YunServer.H and YunClient.h so my code on Uno Wifi and Yun Mini is the same on my file wifi.ino.

but there’s a DEEEEeeeeeeEEEEP mystery…
get prepared…
It doesn’t work on YÙN ! ! ! Whooooosh

Well according to me, even on Arduino Uno Wifi, the wifi is just magic, I think they’ve put some magic powder in a chip.
I just don’t Understand why you must have a path like…
http://arduino.local/arduino/mode
…or…
http://arduino.local/arduino/digital
…if you want it to work. Anyway, if someone knows the magic formula, please teach me and… where is Hogwarts ?

Here is my code:

main.ino

#include "headers/preprocessor.h"


// [...]


void setup() { // SETUP
  delay(5000);
  Serial.begin(115200);
  while(!Serial); // waits for Serial Monitor to open
  Serial.println(F("\rInitialisation"));


  WifiSetup();
  Serial.println(F("done"));

// [...]
  
}// SETUP


void loop(){
  PdateUpdate();
                              
  wf_process(); // HERE IS THE FUNCTION FOR THE WIFI

  tem_led_y(); // témoignage interdiction commutation
  if(modeChange){
    modeChange = false;
    ChangeMode();
  }
}


/****************
 *MAIN FUNCTIONS*/
 
void ChangeMode(){
  if(delayYunTime(stimeDef(ONOFF_DELAY), yunTime, &timeTrigger)){
      Mode = !Mode;// Mode = !Mode
      deplServo();// déploie ou retracte le servo f(boo.bit0) 
      temoignage(); // témoigne du mode de charge     
  }
  else{}
} 

/*MAIN FUNCTIONS*
 ****************/

wifi.ino

void WifiSetup(){
  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("\rWifi available"));
  
}

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(modeChange)  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(current);
}

void wf_contact(){ 
  contact();
}

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

void wf_getd(){
  String d = Client.readStringUntil('/');
  if(d == "state")        wf_state();
  else if(d == "voltage") wf_voltage();
  else if(d == "current") wf_current();
  else                    wf_error();
}
void wf_process(){
  Client = Wifi.accept();
  while(Client.available()){
    if (Client.readStringUntil('/') == "mode")
      wf_switch();
    else
      Serial.println(F("command not found (process)"));//wf_error();
  }
  Client.stop();
}


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

  if (command == "commutation")  wf_commutation();
  else if (command == "get")     wf_getd();
  else                           wf_error();
}

headers/preprocessor.h

#ifndef PREPRO_H
#define PREPRO_H

/****************
 *	LIBRARIES   */


#include <Wire.h>
#include <I2C.h>
#include <time.h>
#include <Servo.h>
#include <Bridge.h>
#include <YunServer.h> 
// password for browser configuration panel is : "doghunter"
  YunServer Wifi;
#include <YunClient.h>
  YunClient Client;
#include <Process.h>

/**	LIBRARIES 	 *
 ****************/
/****************
 *	HEADERS     */
 

#include "structure.h"
#include "prototype.h"

/** 	HEADERS  *
 ****************/
 
/****************
 *	CONSTANTS   */

// [...]

/**	  CONSTANTS  *
 ****************/
#endif

thank you very much for your help !
lov ya♥

Hi everyone !

I fixed it (with the huge help of a coworker) !
By analising the string received from my browser, I found that, at the end, there were no ‘\0’ but a ‘\r\n’ instead. (I didn’t tested on the UNO Wifi but I guess the function BridgeClient::readString() of Arduino Yun is different from the one for UnoWifi.

| 0 | | | 1 | | | 2 | | | 3 | | | 4 | | | 5 | | | 6 | | | 7 | | | 8 | | | 9 | | | 10 | | | 11 | | | 12 |
| - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| 0x63 | | | 0x6F | | | 0x6D | | | 0x6D | | | 0x75 | | | 0x74 | | | 0x61 | | | 0x74 | | | 0x69 | | | 0x6F | | | 0x6E | | | 0x0D | | | 0x0A |
| ‘c’ | | | ‘o’ | | | ‘m’ | | | ‘m’ | | | ‘u’ | | | ‘t’ | | | ‘a’ | | | ‘t’ | | | ‘i’ | | | ‘o’ | | | ‘n’ | | | ‘\r’ | | | ‘\n’ |

So here is my new code for Yùn:

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(){
  Client = Wifi.accept();
  while(Client.available()){
    if (Client.readStringUntil('/') == "mode")
      wf_switch();
    else
      Serial.println(F("command not found (process)"));//wf_error();
  }
  Client.stop();
}


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

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

  for(lop=0;lop<16;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"));
  }
}

the factory firmware of Uno WiFi (based on JeeLabs esp-link) has a webserver which handles the Web Panel. the /arduino/ part of url tels the webserver to route the request to atmega sketch. so simple.

Uno WiFi and Yun are very very different. Uno WiFi has esp8266 and Yun has a chip with Linux.

arduino.org team had the idea to make the atmega part on these boards similar but it wasn't a good idea in my opinion