File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Filter options
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Original file line number Diff line number Diff line change
1
+ #include < ThingSpeak.h>
2
+
3
+
4
+ #include " ESP8266WiFi.h"
5
+ #include " ThingSpeak.h"
6
+
7
+ // Wifi config
8
+ const char ssid[] = " mySSID" ;
9
+ const char password[] = " myPassword" ;
10
+
11
+ // ThingSpeak config
12
+ const unsigned long channel_id = 555842
13
+ const char write_api_key[] = " OC8PZ442W9EPTR3M" ;
14
+
15
+ // WiFi client object
16
+ WiFiClient client;
17
+
18
+
19
+ void setup () {
20
+
21
+ // Initialize Serial
22
+ Serial.begin (9600 );
23
+ delay (100 );
24
+
25
+ // Connect to WiFi
26
+ Serial.print (" Connecting to " );
27
+ Serial.print (ssid);
28
+ WiFi.begin (ssid, password);
29
+ while (WiFi.status () != WL_CONNECTED ){
30
+ delay (500 );
31
+ Serial.print (" ." );
32
+ }
33
+ Serial.println ();
34
+
35
+ // show that we are connected
36
+ Serial.println (" Connected!" );
37
+
38
+ // Connect to ThingSpeak
39
+ ThingSpeak.begin (client);
40
+
41
+ randomSeed (micros ());
42
+ }
43
+
44
+ void loop () {
45
+
46
+ // generate random numbers 1-100
47
+ int rando = random (1 ,101 );
48
+
49
+ // write values to our ThingSoeak channel
50
+ Serial.println (" Posting " +String (rando) + " to ThingSpeak" );
51
+ ThingSpeak.setField (1 , rando);
52
+ ThingSpeak.writeFields (channel_id, write_api_key);
53
+
54
+ delay (30000 );
55
+
56
+
57
+ }
You can’t perform that action at this time.
0 commit comments