-
Notifications
You must be signed in to change notification settings - Fork 1
/
program.ino
77 lines (51 loc) · 1.52 KB
/
program.ino
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
void Connection()
{
mySerial.println("AT");
delay(1000);
mySerial.println("AT+CPIN?");
delay(1000);
mySerial.println("AT+CREG?");
delay(1000);
mySerial.println("AT+CGATT?");
delay(1000);
mySerial.println("AT+CIPSHUT");
delay(1000);
mySerial.println("AT+CIPSTATUS");
delay(2000);
mySerial.println("AT+CIPMUX=0");
delay(2000);
ShowSerialData();
mySerial.println("AT+CSTT=\"internet\"");//start task and setting the APN,
delay(1000);
ShowSerialData();
mySerial.println("AT+CIICR");//bring up wireless connection
delay(3000);
ShowSerialData();
mySerial.println("AT+CIFSR");//get local IP adress
delay(2000);
ShowSerialData();
}
void Send2thingspeak(float PPM,float Gasvalue)
{
mySerial.println("AT+CIPSPRT=0");
delay(3000);
ShowSerialData();
mySerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection
delay(6000);
ShowSerialData();
mySerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();
String str="GET http://api.thingspeak.com/update?api_key=T6JWVAB9BXBZRWUV&field1=" + String(PPM)+"&field2=" + String(Gasvalue);
mySerial.println(str);//begin send data to remote server
delay(4000);
ShowSerialData();
mySerial.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
mySerial.println();
}
void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}