Go Down

Topic: wifi post can't find my error in my headers (Read 520 times) previous topic - next topic

pikeymick

Jan 05, 2013, 06:32 am Last Edit: Jan 05, 2013, 08:41 am by pikeymick Reason: 1
I'm making a post to my servlet (the servlet works with a url get, and via jquery), I can't figure out where my error is in how my headers are written. The server isn't getting the payload "content"... thanks for your help.

The server returns 200, and I'm getting through I'm just not getting my "value=********"

Code: [Select]


#include <SPI.h>
#include <WiFi.h>

char ssid[] = "##########"; //  your network SSID (name)
char pass[] = "*********";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(192,168,10,149);  // numeric IP for Google (no DNS)

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;

void setup() {
 Serial.begin(9600);

 // attempt to connect to Wifi network:
 while ( status != WL_CONNECTED) {
   Serial.println("Attempting to connect to SSID: ");
   Serial.println(ssid);
   status = WiFi.begin(ssid, pass);
   // wait 10 seconds for connection:
   delay(10000);
 }
 Serial.println("Connected to wifi");
 printWifiStatus();
 sendData("998986568");
}

void loop() {
 
 // if there's incoming data from the net connection.
 // send it out the serial port.  This is for debugging
 // purposes only:
 if (client.available()) {
   char c = client.read();
   Serial.println(c);
 }

 // if you're not connected, and ten seconds have passed since
 // your last connection, then connect again and send data:
 if(!client.connected())
 {
   Serial.println();
   Serial.println("disconnecting.");
   client.stop();
   //sendData(dataString);
   for(;;)
       ;
 }
}

// this method makes a HTTP connection to the server:
void sendData(String thisData) {
 // if there's a successful connection:
 Serial.println("send data");
 if (client.connect(server, 8080)) {
   String content = "value=06008E2496";// + thisData;
   Serial.println(content);
   Serial.println("connected");
   delay(50);
   // send the HTTP PUT request:
   client.println("POST /hos HTTP/1.1");
   client.println("Host:localhost");
   client.println("Connection:Keep-Alive");
   client.println("Cache-Control:max-age=0");
   client.println("Content-Type: application/x-www-form-urlencoded\n");
   client.println("Content-Length: ");
   client.println(content.length());
   client.println("\n\n");
   client.println(content);
 }
 else {
   // if you couldn't make a connection:
   Serial.println("cform onnection failed");
   Serial.println();
   Serial.println("disconnecting.");
   client.stop();
 }
}


void printWifiStatus() {
 // print the SSID of the network you're attached to:
 Serial.println("SSID: ");
 Serial.println(WiFi.SSID());

 // print your WiFi shield's IP address:
 IPAddress ip = WiFi.localIP();
 Serial.println("IP Address: ");
 Serial.println(ip);

 // print the received signal strength:
 long rssi = WiFi.RSSI();
 Serial.println("signal strength (RSSI):");
 Serial.println(rssi);
 Serial.println(" dBm");
}



PaulS

Quote
The server returns 200, and I'm getting through I'm just not getting my "value=********"


Code: [Select]
    //sendData(dataString);
Gee, I wonder why.

pikeymick

Wow really? So I'm guessing you just jumped at the first chance to criticize and didn't notice that it was moved to setup()? Gee thanks for your insight.

PaulS

Quote
So I'm guessing you just jumped at the first chance to criticize and didn't notice that it was moved to setup()?

No, I didn't. I'm sorry.

Code: [Select]
    client.println("\n\n");
I think this should be \r\n, not \n\n.

Go Up