Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <WiFiClient.h>
  2. #include <ESP8266WebServer.h>
  3. #include <ESP8266HTTPClient.h>
  4.  
  5. int Integer = 0 ;
  6. void sendHttpRequest( String _serverHost,String _name, int _data ) {
  7.   String _send;
  8.   HTTPClient http;
  9.   _serverHost="http://"+_serverHost+"/";
  10.   http.begin(_serverHost);
  11.   http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  12.   _send = _name+ "="+  String(_data);
  13.   Serial.println("- data stream: "+_send);
  14.   http.POST(_send);
  15.   http.writeToStream(&Serial);
  16.   http.end();
  17. }
  18.  
  19.  
  20. void setup()
  21. {
  22.   Serial.begin(9600);
  23.   WiFi.begin ( "RESEAU", "12345678" );
  24.   while ( WiFi.status() != WL_CONNECTED ) {  
  25.     delay ( 500 );
  26.     Serial.print ( "." );
  27.   }
  28.   Serial.println ( "" );
  29.   Serial.print ( "Connected to " );
  30.   Serial.println ( "RESEAU" );  
  31.   Serial.print ( "IP address: " );
  32.   Serial.println ( WiFi.localIP() );
  33.  
  34. }
  35.  
  36. void loop()
  37. {
  38.   Integer =     random( 0 , 100 ) ;
  39.   sendHttpRequest( "192.168.4.1","Nom",Integer );
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement