XML string

I posted in an earlier forum about an issue with null, I figured that out. Now I am getting an error of -3 when I send the post request (towards the end of the code). It appears to connect using the “post” function. My theory is that the XML is not being transmitted correctly. Any help would be appreciated. Thank you. Code is below:

#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <String.h>

//MAC address of ethernet
byte mac = { 0x90, 0xA2, 0xDA, 0x0D, 0xB2, 0xAE };

int readlight(int lt){

float tmpflt = (float)lt1.1/1024;
int percent = 100

if(percent > 100)
percent = 100;
if(percent < 0 )
percent = 0;

return percent;

int readtemp(int tm){

float tmpflt = (float)tm*1.1/1024;

int Rth = 0;
boolean done = false;

while(done == false){

float res1 = tmpflt*((float)Rth+1000);
float res2 = (float)Rth*3.3;

if(res2 > res1)
done = true;
else Rth+=1;

float tmptemp = 25.0+(float)(Rth-500)(-0.05);
float fahrenheight = 32+tmptemp

int tmpout = (int)fahrenheight;

return tmpout;


int readfromserial(){


if(Serial.available() > 0)
return Serial.read();

int readvalue(int sensorid, int mode){

const double ref = 1.1;

int length;
int address;
int signalstrength;
byte tmp;

double voltage0, voltage1;

boolean done = false;

while(done == false){
if(Serial.read() == 0x7E){

int lengthh = readfromserial();
int lengthl = readfromserial();
length = 256*lengthh+lengthl;

if(readfromserial() == 0x83){

int addressh = readfromserial();
int addressl = readfromserial();
address = 256*addressh+addressl;

if(address == (sensorid-1)){
done =true;

signalstrength = readfromserial();

for(int i = 1;i <= 6; i++){
tmp = readfromserial();

int ad0h = readfromserial();
int ad0l = readfromserial();
int ad0tmp = 256*ad0h+ad0l;

int ad1h = readfromserial();
int ad1l = readfromserial();
int ad1tmp = 256*ad1h+ad1l;

if(mode == 0)
return readlight(ad0tmp);

if(mode == 1)
return readtemp(ad1tmp);


return -1;

EthernetClient c;
HttpClient http(c);

void setup() {
// put your setup code here, to run once:

while (Ethernet.begin(mac) != 1)
Serial.println(“Error getting IP address via DHCP, trying again…”);


void loop() {
// main program loop

// read values from sensors
// int sensorValue1 = readvalue(1,0);
// int sensorValue2 = readvalue(1,1);
int sensorValue3 = 5;//readvalue(2,0);
int sensorValue4 = 5;//readvalue(2,1);
int sensorValue5 = 6;//readvalue(3,0);
int sensorValue6 = 6;//readvalue(3,1);
int sensorValue7 = 7;//readvalue(4,0);
int sensorValue8 = 7;//readvalue(4,1);

Serial.println(“sensor readings”);

int err = 0;

//err=http.put(kHostname, kPath);

//generate url
char* url = “http://ds.sidnow.com/SidAppService.svc/putDeviceData/?&apikey=PIRH2OOl@AlvtFxuLEJ4MA==&userId=111&status=1&type=mobile”;

err=http.post(“ds.sidnow.com/”, 80, url);

if(err == 0){

Serial.println(“startedRequest ok”);

//apikey/token key
http.sendHeader(“apikey”, “uQ9i/ROEOc5Z1AltY3uSUnbMgQtiktP7U4tXXxB1Ep4=”);

//char* xmlStrChars;

//xmlStr.toCharArray(xmlStrChars, 1000);
//http.sendHeader(“deviceData”, xmlStrChars);

//write xml directly to ethernet out
c.println("deviceData: <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");


err = http.responseStatusCode();

if (err >= 0)
Serial.print("Got status code: ");

// Usually you’d check that the response code is 200 or a
// similar “success” code (200-299) before carrying on,
// but we’ll print out whatever response we get
Serial.print("Getting response failed: ");
Serial.print("Connect failed: ");


// Wait for a bit before updating things again

Your request should probably be:

err=http.post("ds.sidnow.com", 80, url);

ds.sidnow.com/ is not a valid host name so may be the problem. Can't be sure though as I don't know what library you're using! :) Also next time please put all your code in code tags: [code][/code]

I am getting an error of -3 when I send the post request (towards the end of the code). It appears to connect using the “post” function.

I can see the call to http.post() followed by code that writes some request headers and a body, but I don’t know what else is going on or where the error occurs - there’s quite a lot of code there.

Can you reproduce the problem with a minimal sketch that does the least work necessary to initialise the network, perform the HTTP Post and demonstrate the problem? Include print statements to show what’s working and what’s failing, and include the output you get from them.