Go Down

Topic: YunClient removes URL parameters (Read 1 time) previous topic - next topic

alessandro_montanari

Hi all,
I would like to pass some parameters from a web page to the sketch that is running on the mcu, something like this:
http://192.168.0.100/arduino/do/?param=value

To do this I am using this code in the loop:
Code: [Select]

...
YunClient client = server.accept();
if (client) {
    if (client.readStringUntil('/').startsWith("do")) {
      String command = client.readString();
      Serial.println(command);
      ....
    }
    client.stop();
  }


But unfortunately the value of command is always empty, instead I was expecting something like this "?param=value".

Do you know if there is another way to obtain that parameter?

Thanks!!

sonnyyu

Code: [Select]
...
YunClient client = server.accept();
if (client) {
    String command = client.readStringUntil('/');
    command.trim();        //kill whitespace
    Serial.println(command);
   
    String parameter = client.readString();
    parameter.trim();        //kill whitespace
    Serial.println(parameter);
    client.stop();
  }


http://192.168.0.101/arduino/do/123

alessandro_montanari

Thanks sonnyyu, that is exactly what I did to solve the problem, even if I have to send also some json data so I did something like this:
http://192.168.0.100/arduino/do/123/{"data1":1, "data2":2}/

Now I was thinking this: at the moment I am writing all of my code on the mcu side, keeping the Linino side unused, and I am hitting some memory problems on the mcu.
My idea would be to use as much as possible the Linino side (for the communication and data processing for example) and use the mcu side only for the hardware-related stuff (control of the pins for example).  So I am wondering which is the best framework to intercept web service requests in order to process them and then pass only the necessary informations to the mcu. This would also simplify the transmission of json data because it can be inserted in the request as payload avoiding putting it in the URL as above.
At the beginning I thought to use node.js but it requires installation so now I am looking at some python solutions.
Any advise in this direction is welcomed.

Go Up