JSON from arduino to PHP server

From Wiki2
Revision as of 15:12, 12 January 2013 by Tim (talk | contribs) (Created page with "=====JSON from arduino to PHP server===== Encoding pin values in JSON: <sytaxhighlight> // last pieces of the HTTP PUT request: client.println("Content-Type: applicati...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
JSON from arduino to PHP server

Encoding pin values in JSON: <sytaxhighlight>

   // last pieces of the HTTP PUT request:
   client.println("Content-Type: application/json");
   client.println("Connection: close");
   client.println();
     
   client.print("{"); 
   // here's the actual content of the PUT request:
   for (int analogChannel = 2; analogChannel < 6; analogChannel++) {
     int sensorReading = analogRead(analogChannel);    
     String schan = "\""+ sen + analogChannel + "\":";
     client.print(schan);
     client.print(sensorReading);
     if (analogChannel != 5) {
         client.print(",");
     }
    }
    client.println("}");

</syntaxhighlight> <sytaxhighlight> </syntaxhighlight> <sytaxhighlight> </syntaxhighlight> <sytaxhighlight> </syntaxhighlight>