返回顶部

收藏

来自Arduino(WiFly 图书馆)的HTTP POST

更多
#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 );
}

标签:c

收藏

0人收藏

支持

0

反对

0

发表评论