Posted By

parkerkrhoyt on 07/26/11


Tagged

http protocol post wireless arduino wifly


Versions (?)

HTTP POST from Arduino (WiFly Library)


 / 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.

  1. #include "WiFly.h"
  2. #include "Credentials.h"
  3.  
  4. Client client( "ketnerlake.com", 80 );
  5.  
  6. int looped = 0;
  7.  
  8. void setup()
  9. {
  10. Serial.begin( 9600 );
  11. WiFly.begin();
  12.  
  13. if( !WiFly.join( ssid, passphrase ) )
  14. {
  15. Serial.println( "Association failed." );
  16.  
  17. while( 1 )
  18. {
  19. // Hang on failure.
  20. }
  21. }
  22. }
  23.  
  24. void loop()
  25. {
  26. String data = "data=$,WEATHER,79.5,51,59.7,29.366,2.8,0.0,270,0.00,0.00,*";
  27.  
  28. if( client.connect() )
  29. {
  30. Serial.println( data );
  31.  
  32. client.println( "POST /sensors/intercept.cfm HTTP/1.1" );
  33. client.println( "Host: www.ketnerlake.com" );
  34. client.println( "Content-Type: application/x-www-form-urlencoded" );
  35. client.println( "Connection: close" );
  36. client.print( "Content-Length: " );
  37. client.println( data.length() );
  38. client.println();
  39. client.print( data );
  40. client.println();
  41. }
  42.  
  43. delay( 5000 );
  44. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: elona on October 6, 2011

This was such a very useful article. Thank you for posting this thing. Great job! Got to go! I need to write more of my custom essays.

You need to login to post a comment.