-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_code.c
51 lines (51 loc) · 944 Bytes
/
source_code.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
ESP8266 Code
#include “ThinkSpeak.h
#include <ESP8266WiFi.h>
char networkname[] = “”; // your network name
char passcode[] = “”; // your passcode
WiFiClient client;
unsigned long tsChannelID = ; // ThingSpeak Channel ID
const char * tsWriteAPIKey = “”; //ThingSpeak Write API Key
String airQuaility = “”;
const int fieldOne = 1;
void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
thingSpeak();
}
void loop()
{
thingSpeak();
if (Serial.available() > 0)
{
while (Serial.available() > 0)
{
int inChar = Serial.read();
airQuaility += (char)inChar;
}
}
pushData();
}
void thingSpeak()
{
if (WiFi.status() != WL_CONNECTED)
{
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(networkname, passcode);
delay(5000);
}
}
}
void pushData()
{
int getData = ThingSpeak.writeField(tsChannelID, fieldOne, airQuaility, tsWriteAPIKey);
if (getData != 200)
{
delay(15000);
pushData();
}
airQuaility = “”;
}