59 lines
1.4 KiB
Arduino
59 lines
1.4 KiB
Arduino
|
/*
|
||
|
* This sketch sends data via HTTP GET requests to data.sparkfun.com service.
|
||
|
*
|
||
|
* You need to get streamId and privateKey at data.sparkfun.com and paste them
|
||
|
* below. Or just customize this script to talk to other HTTP servers.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include <WiFi.h>
|
||
|
|
||
|
const char* ssid = "yourssid";
|
||
|
const char* password = "12345678";
|
||
|
const char* host = "192.168.4.1";
|
||
|
WiFiClient client;
|
||
|
uint16_t port = 9100;
|
||
|
uint8_t temp;
|
||
|
uint8_t buffer[512];
|
||
|
void setup()
|
||
|
{
|
||
|
Serial.begin(921600);
|
||
|
delay(10);
|
||
|
// We start by connecting to a WiFi network
|
||
|
Serial.println();
|
||
|
Serial.println();
|
||
|
Serial.print("Connecting to ");
|
||
|
Serial.println(ssid);
|
||
|
WiFi.begin(ssid, password);
|
||
|
while (WiFi.status() != WL_CONNECTED) {
|
||
|
delay(500);
|
||
|
Serial.print(".");
|
||
|
}
|
||
|
Serial.println("");
|
||
|
Serial.println("WiFi connected");
|
||
|
Serial.println("IP address: ");
|
||
|
Serial.println(WiFi.localIP());
|
||
|
}
|
||
|
|
||
|
void loop()
|
||
|
{
|
||
|
// Use WiFiClient class to create TCP connections
|
||
|
if (client.connected()) {
|
||
|
while (client.available() != 0) {
|
||
|
if (client.available()<=512)
|
||
|
{
|
||
|
int cnt = client.available();
|
||
|
client.read(buffer,cnt);
|
||
|
Serial.write(buffer,cnt);
|
||
|
}else{
|
||
|
client.read(buffer,512);
|
||
|
Serial.write(buffer,512);
|
||
|
}
|
||
|
}
|
||
|
}else{
|
||
|
Serial.println("connecting to ");
|
||
|
Serial.printf("%s %d\n",host,port);
|
||
|
client.connect(host, port);
|
||
|
delay(500);
|
||
|
}
|
||
|
}
|