Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <ESP8266WiFi.h>
const char* ssid = "ssid";
const char* password = "password";
const char* host = "192.168.1.xx"; // server host
const int port = 8000;
void setup()
{
Serial.begin(9600);
delay(10);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void report(char *query)
{
WiFiClient client;
if (!client.connect(host, port)) {
return;
}
String path = "/mix1?";
path += query;
client.print(String("GET ") + path + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned int timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 1000) {
break;
}
}
client.stop();
}
void loop()
{
int i, j;
char c, b[4][16], q[256];
i = j = 0;
while (1) {
if (Serial.available() > 0) {
c = Serial.read();
if (c == ',') {
b[j][i] = 0x0;
j++;
i = 0;
} else if (c == ';') {
b[j][i] = 0x0;
break;
} else {
b[j][i] = c;
i++;
}
}
}
sprintf(q, "dht11t=%s&pressure=%s&pm25=%s&mq135=%s", b[0], b[1], b[2], b[3]);
Serial.println(q);
report(q);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment