WiShield POSTing and JSON parsing

My original post is here: Asynclabs.com.

I’m am having some basic C trouble, along with some other more advanced stuff.

I can POST to my own API, but I am having trouble adding a concatenated variable (basic C stuff…still learning), as well as with parsing a JSON returned array (200 status returned along with some other info).

I use a modified WebClient Sketch with a WiShield, and it doesn’t compile…I’ve tried every combination my young C mind can think of. For example:

char mqttCode[11]; //then I run some stuff and get an RFID badge in form of a string

//the original, non-concatenated post request looks like below, and works
//const prog_char twitter[] PROGMEM = {"POST /APICode/api/Sensor/ HTTP/1.1\r\nUser-Agent: uIP/1.0\r\nHost: myurl.com\r\nContent-Length: 24\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nFacebookBadge=1234567899"};

strcpy(one, "POST /APICode/Sensor/ HTTP/1.1\r\nUser-Agent: uIP/1.0\r\nHost: myurl.com\r\nContent-Length: 25\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nFacebookBadge=");
char posting;
posting = strcat(one, mqttCode);
const prog_char twitter[] PROGMEM = {posting};

void loop()
//if something happens, i post again
const prog_char twitter[] PROGMEM = {posting};

I’m also unsure about what function to use to get returned JSON information from my POST request (which I imagine will come back with headers included, and I have no idea where to look for parsing information). Help!

strcpy(one, "POST /APICode/Sensor/ HTTP/1.1\r\nUser-Agent: uIP/1.0\r\nHost: myurl.com\r\nContent-Length: 25\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nFacebookBadge=");

Executable code, like this call to strcpy, need to be inside a function.

const prog_char twitter[] PROGMEM = {posting};

PROGMEM is used for things that will not change for the life of the program. As a local variable inside the loop function, this is certainly not the case.

char posting;
posting = strcat(one, mqttCode);

Concatenating that long string of characters with another string, and stuffing them into a single character is going to be quite a trick.

There really is no reason to concatenate anything. When you POST, the POST command is not complete until a carriage return is send. So, just send the first part, which can be just a constant string:

Whatever.print("The long string goes here");

As for parsing the return data, we'll need to wait to see what kind of data you get in response to the POST, first.

Very helpful. I’m now getting a header back and a JSON array, which I need to parse the session_id from (which i use to POST). Can I ignore the header and use the C JSON library?

Here’s what I get retured to serial:

HTTP/1.1 200 OK
Date: Mon, 16 Aug 2010 23:33:47 GMT
Server: Apache/2.2.9 (Fedora)
X-Powered-By: PHP/5.2.6
Content-Length: 291
Connection: close
text/html; charset=UTF-8


My current code:

//function that prints data from the server
void printData(char* data, int len) {
  //print the data returned by the server
  //note that the data is not null-terminated, may be broken up into smaller packets, and includes the HTTP header. 
  while (len-- > 0) {

GETrequest getSession(ipaddr, port, hostname, newURI);

void setup() {
  //initialize wiserver (we'll pass null for the page serving function since we don't need to serve web pages) 

  //enable serial output and ask wierver to generate log messages (optional)

  //have the processData function called when data is returned by the server

// Time (in millis) when the data should be retrieved 
long updateTime = 0;

void loop(){
  // Check if it's time to get an update
  //if (millis() >= updateTime) {
  // Get another update one min from now
  //  updateTime += 1000 * 20;

  // Run WiServer