Making variable accessible with JSON


How can I do this?

Write some code to parse the incoming HTTP request and extract the request parameters using the encoding scheme you’re proposing.

Write some code to perform the requested operation.

Write some code to send the results of the operation back to the client in the format that you’re proposing.


The below code is for a serial setup, but the same process can be used to parse data in a String from a server returning data to the arduino.

//zoomkat 11-12-13 String capture and parsing  
//from serial port input (via serial monitor)
//and print result out serial port
//copy test strings and use ctrl/v to paste in
//serial monitor if desired
// * is used as the data string delimiter
// , is used to delimit individual data 

String readString; //main captured String 
String angle; //data String
String fuel;
String speed1;
String altidude;

int ind1; // , locations
int ind2;
int ind3;
int ind4;

void setup() {
  Serial.println("serial delimit test 11-12-13"); // so I can keep track of what is loaded

void loop() {

  //expect a string like 90,low,15.6,125*
  //or 130,hi,7.2,389*

  if (Serial.available())  {
    char c =;  //gets one byte from serial buffer
    if (c == '*') {
      //do stuff
      Serial.print("captured String is : "); 
      Serial.println(readString); //prints string to serial port out
      ind1 = readString.indexOf(',');  //finds location of first ,
      angle = readString.substring(0, ind1);   //captures first data String
      ind2 = readString.indexOf(',', ind1+1 );   //finds location of second ,
      fuel = readString.substring(ind1+1, ind2+1);   //captures second data String
      ind3 = readString.indexOf(',', ind2+1 );
      speed1 = readString.substring(ind2+1, ind3+1);
      ind4 = readString.indexOf(',', ind3+1 );
      altidude = readString.substring(ind3+1); //captures remain part of data after last ,

      Serial.print("angle = ");
      Serial.print("fuel = ");
      Serial.print("speed = ");
      Serial.print("altidude = ");
      readString=""; //clears variable for new input
    else {     
      readString += c; //makes the string readString


Are you going to run the web server on the Linux processor? If so, I guess it will need to use the bridge library to communicate with the AVR processor which does the I/O. Presumably there are YUN examples which show how to achieve that communication.

Perhaps the below web site has some useful info.


Dawiinci: The webserver already runs. I just don't know how to make variables accessible.

Below are some json tutorials that might help you develop a web page that includes json functions.


So do you want the arduino or the webbrowser to parse the json ? The browser can use JavaScript to parse and you have to write something for the arduino to parse the string.

Dawiinci: I guess there has to be an easy way doing this.

I would guess so too. You'd need to look at the web server implementation and understand how it obtains the data it currently publishes, and then extend that implementation to publish the extra data you want.

Dawiinci: It's not about making a website, I only want variable int x to be available over http. The Arduino Yun ALREADY delivers this functionality with all inputs, so I guess there has to be an easy way doing this.

The "I only want variable int x to be available over http" is easy. The variable can be returned from a server that has the variable available for sending back to a client, or a variable can be sent by a client as a GET or POST request to a server. The rest of your request is some what "soup sandwich" as to what you actually want and is not easily understood.