/ Published in: C
This snippet will send an HTTP POST from an Arduino using the WiFly library. The library is in early alpha, and is a port from the ethernet shield library. The code here should work with either. The critical part is the size of the data to send, and the line-breaks in the right places.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#include "WiFly.h" #include "Credentials.h" Client client( "ketnerlake.com", 80 ); int looped = 0; void setup() { Serial.begin( 9600 ); WiFly.begin(); if( !WiFly.join( ssid, passphrase ) ) { Serial.println( "Association failed." ); while( 1 ) { // Hang on failure. } } } void loop() { String data = "data=$,WEATHER,79.5,51,59.7,29.366,2.8,0.0,270,0.00,0.00,*"; if( client.connect() ) { Serial.println( data ); client.println( "POST /sensors/intercept.cfm HTTP/1.1" ); client.println( "Host: www.ketnerlake.com" ); client.println( "Content-Type: application/x-www-form-urlencoded" ); client.println( "Connection: close" ); client.print( "Content-Length: " ); client.println( data.length() ); client.println(); client.print( data ); client.println(); } delay( 5000 ); }