Skip to content

Commit 0195179

Browse files
Add files via upload
changes for v1.5.0
1 parent 8870424 commit 0195179

File tree

40 files changed

+1445
-317
lines changed

40 files changed

+1445
-317
lines changed

examples/ArduinoEthernet/ReadField/ReadField.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525

2626
#include "ThingSpeak.h"
27-
#include <SPI.h>
2827
#include <Ethernet.h>
2928
#include "secrets.h"
3029

examples/ArduinoEthernet/WriteMultipleFields/WriteMultipleFields.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424

2525
#include "ThingSpeak.h"
26-
#include <SPI.h>
2726
#include <Ethernet.h>
2827
#include "secrets.h"
2928

examples/ArduinoEthernet/WriteSingleField/WriteSingleField.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424

2525
#include "ThingSpeak.h"
26-
#include <SPI.h>
2726
#include <Ethernet.h>
2827
#include "secrets.h"
2928

examples/ArduinoMKR1000/ReadField/ReadField.ino

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
!!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!!
1111
1212
Note:
13-
- Requires WiFi101 library. Use the WiFi101 library version 0.13.0 or older. WiFi101 library versions 0.14.0 and newer have a bug
14-
that stops this ThingSpeak library from working properly.
13+
- Requires WiFi101 library version 0.15.3 or newer.
1514
- This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly.
1615
1716
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and
@@ -26,7 +25,6 @@
2625
*/
2726

2827
#include "ThingSpeak.h"
29-
#include <SPI.h>
3028
#include <WiFi101.h>
3129
#include "secrets.h"
3230

examples/ArduinoMKR1000/WriteMultipleFields/WriteMultipleFields.ino

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
!!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!!
99
1010
Note:
11-
- Requires WiFi101 library. Use the WiFi101 library version 0.13.0 or older. WiFi101 library versions 0.14.0 and newer have a bug
12-
that stops this ThingSpeak library from working properly.
11+
- Requires WiFi101 library version 0.15.3 or newer.
1312
- This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly.
1413
1514
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and
@@ -24,7 +23,6 @@
2423
*/
2524

2625
#include "ThingSpeak.h"
27-
#include <SPI.h>
2826
#include <WiFi101.h>
2927
#include "secrets.h"
3028

examples/ArduinoMKR1000/WriteSingleField/WriteSingleField.ino

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
!!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!!
99
1010
Note:
11-
- Requires WiFi101 library. Use the WiFi101 library version 0.13.0 or older. WiFi101 library versions 0.14.0 and newer have a bug
12-
that stops this ThingSpeak library from working properly.
11+
- Requires WiFi101 library version 0.15.3 or newer.
1312
- This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly.
1413
1514
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and
@@ -24,7 +23,6 @@
2423
*/
2524

2625
#include "ThingSpeak.h"
27-
#include <SPI.h>
2826
#include <WiFi101.h>
2927
#include "secrets.h"
3028

examples/ArduinoMKRETHShield/ReadField/ReadField.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525

2626
#include "ThingSpeak.h"
27-
#include <SPI.h>
2827
#include <Ethernet.h>
2928
#include "secrets.h"
3029

examples/ArduinoMKRETHShield/WriteMultipleFields/WriteMultipleFields.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323

2424
#include "ThingSpeak.h"
25-
#include <SPI.h>
2625
#include <Ethernet.h>
2726
#include "secrets.h"
2827

examples/ArduinoMKRETHShield/WriteSingleField/WriteSingleField.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323

2424
#include "ThingSpeak.h"
25-
#include <SPI.h>
2625
#include <Ethernet.h>
2726
#include "secrets.h"
2827

examples/ArduinoMKRVIDOR4000/ReadField/ReadField.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626

2727
#include "ThingSpeak.h"
28-
#include <SPI.h>
2928
#include <WiFiNINA.h>
3029
#include "secrets.h"
3130

examples/ArduinoMKRVIDOR4000/WriteMultipleFields/WriteMultipleFields.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
#include "ThingSpeak.h"
26-
#include <SPI.h>
2726
#include <WiFiNINA.h>
2827
#include "secrets.h"
2928

examples/ArduinoMKRVIDOR4000/WriteSingleField/WriteSingleField.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
#include "ThingSpeak.h"
26-
#include <SPI.h>
2726
#include <WiFiNINA.h>
2827
#include "secrets.h"
2928

examples/ArduinoMKRWiFi1010/ReadField/ReadField.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
*/
2626

2727
#include "ThingSpeak.h"
28-
#include <SPI.h>
2928
#include <WiFiNINA.h>
3029
#include "secrets.h"
3130

examples/ArduinoMKRWiFi1010/WriteMultipleFields/WriteMultipleFields.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
#include "ThingSpeak.h"
26-
#include <SPI.h>
2726
#include <WiFiNINA.h>
2827
#include "secrets.h"
2928

examples/ArduinoMKRWiFi1010/WriteSingleField/WriteSingleField.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
*/
2424

2525
#include "ThingSpeak.h"
26-
#include <SPI.h>
2726
#include <WiFiNINA.h>
2827
#include "secrets.h"
2928

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
ReadField
3+
4+
Description: Demonstates reading from a public channel which requires no API key and reading from a private channel which requires a read API key.
5+
The value read from the public channel is the current outside temperature at MathWorks headquaters in Natick, MA. The value from the
6+
private channel is an example counter that increments every 10 seconds.
7+
8+
Hardware: Arduino Uno WiFi Rev2
9+
10+
!!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!!
11+
12+
Note:
13+
- Requires WiFiNINA library.
14+
- This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly.
15+
16+
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and
17+
analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel.
18+
19+
Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed.
20+
See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation.
21+
22+
For licensing information, see the accompanying license file.
23+
24+
Copyright 2019, The MathWorks, Inc.
25+
*/
26+
27+
#include "ThingSpeak.h"
28+
#include <WiFiNINA.h>
29+
#include "secrets.h"
30+
31+
char ssid[] = SECRET_SSID; // your network SSID (name)
32+
char pass[] = SECRET_PASS; // your network password
33+
int keyIndex = 0; // your network key Index number (needed only for WEP)
34+
WiFiClient client;
35+
36+
// Weather station channel details
37+
unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION;
38+
unsigned int temperatureFieldNumber = 4;
39+
40+
// Counting channel details
41+
unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER;
42+
const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER;
43+
unsigned int counterFieldNumber = 1;
44+
45+
void setup() {
46+
Serial.begin(115200); // Initialize serial
47+
48+
// check for the WiFi module:
49+
if (WiFi.status() == WL_NO_MODULE) {
50+
Serial.println("Communication with WiFi module failed!");
51+
// don't continue
52+
while (true);
53+
}
54+
55+
String fv = WiFi.firmwareVersion();
56+
if (fv != "1.0.0") {
57+
Serial.println("Please upgrade the firmware");
58+
}
59+
60+
ThingSpeak.begin(client); //Initialize ThingSpeak
61+
}
62+
63+
void loop() {
64+
65+
int statusCode = 0;
66+
67+
// Connect or reconnect to WiFi
68+
if(WiFi.status() != WL_CONNECTED){
69+
Serial.print("Attempting to connect to SSID: ");
70+
Serial.println(SECRET_SSID);
71+
while(WiFi.status() != WL_CONNECTED){
72+
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
73+
Serial.print(".");
74+
delay(5000);
75+
}
76+
Serial.println("\nConnected");
77+
}
78+
79+
// Read in field 4 of the public channel recording the temperature
80+
float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber);
81+
82+
// Check the status of the read operation to see if it was successful
83+
statusCode = ThingSpeak.getLastReadStatus();
84+
if(statusCode == 200){
85+
Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F");
86+
}
87+
else{
88+
Serial.println("Problem reading channel. HTTP error code " + String(statusCode));
89+
}
90+
91+
delay(15000); // No need to read the temperature too often.
92+
93+
// Read in field 1 of the private channel which is a counter
94+
long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey);
95+
96+
// Check the status of the read operation to see if it was successful
97+
statusCode = ThingSpeak.getLastReadStatus();
98+
if(statusCode == 200){
99+
Serial.println("Counter: " + String(count));
100+
}
101+
else{
102+
Serial.println("Problem reading channel. HTTP error code " + String(statusCode));
103+
}
104+
105+
delay(15000); // No need to read the counter too often.
106+
107+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Use this file to store all of the private credentials
2+
// and connection details
3+
4+
#define SECRET_SSID "MySSID" // replace MySSID with your WiFi network name
5+
#define SECRET_PASS "MyPassword" // replace MyPassword with your WiFi password
6+
7+
#define SECRET_CH_ID_WEATHER_STATION 12397 //MathWorks weather station
8+
9+
#define SECRET_CH_ID_COUNTER 298725 //Test channel for counting
10+
#define SECRET_READ_APIKEY_COUNTER "SODG0O2UZVGKWAWG" //API Key for Test channel
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
WriteMultipleFields
3+
4+
Description: Writes values to fields 1,2,3,4 and status in a single ThingSpeak update every 20 seconds.
5+
6+
Hardware: Arduino Uno WiFi Rev2
7+
8+
!!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!!
9+
10+
Note:
11+
- Requires WiFiNINA library.
12+
- This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly.
13+
14+
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and
15+
analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel.
16+
17+
Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed.
18+
See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation.
19+
20+
For licensing information, see the accompanying license file.
21+
22+
Copyright 2018, The MathWorks, Inc.
23+
*/
24+
25+
#include "ThingSpeak.h"
26+
#include <WiFiNINA.h>
27+
#include "secrets.h"
28+
29+
char ssid[] = SECRET_SSID; // your network SSID (name)
30+
char pass[] = SECRET_PASS; // your network password
31+
int keyIndex = 0; // your network key Index number (needed only for WEP)
32+
WiFiClient client;
33+
34+
unsigned long myChannelNumber = SECRET_CH_ID;
35+
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
36+
37+
// Initialize our values
38+
int number1 = 0;
39+
int number2 = random(0,100);
40+
int number3 = random(0,100);
41+
int number4 = random(0,100);
42+
String myStatus = "";
43+
44+
void setup() {
45+
Serial.begin(115200); // Initialize serial
46+
47+
// check for the WiFi module:
48+
if (WiFi.status() == WL_NO_MODULE) {
49+
Serial.println("Communication with WiFi module failed!");
50+
// don't continue
51+
while (true);
52+
}
53+
54+
String fv = WiFi.firmwareVersion();
55+
if (fv != "1.0.0") {
56+
Serial.println("Please upgrade the firmware");
57+
}
58+
59+
ThingSpeak.begin(client); //Initialize ThingSpeak
60+
}
61+
62+
void loop() {
63+
64+
// Connect or reconnect to WiFi
65+
if(WiFi.status() != WL_CONNECTED){
66+
Serial.print("Attempting to connect to SSID: ");
67+
Serial.println(SECRET_SSID);
68+
while(WiFi.status() != WL_CONNECTED){
69+
WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network
70+
Serial.print(".");
71+
delay(5000);
72+
}
73+
Serial.println("\nConnected.");
74+
}
75+
76+
// set the fields with the values
77+
ThingSpeak.setField(1, number1);
78+
ThingSpeak.setField(2, number2);
79+
ThingSpeak.setField(3, number3);
80+
ThingSpeak.setField(4, number4);
81+
82+
// figure out the status message
83+
if(number1 > number2){
84+
myStatus = String("field1 is greater than field2");
85+
}
86+
else if(number1 < number2){
87+
myStatus = String("field1 is less than field2");
88+
}
89+
else{
90+
myStatus = String("field1 equals field2");
91+
}
92+
93+
// set the status
94+
ThingSpeak.setStatus(myStatus);
95+
96+
// write to the ThingSpeak channel
97+
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
98+
if(x == 200){
99+
Serial.println("Channel update successful.");
100+
}
101+
else{
102+
Serial.println("Problem updating channel. HTTP error code " + String(x));
103+
}
104+
105+
// change the values
106+
number1++;
107+
if(number1 > 99){
108+
number1 = 0;
109+
}
110+
number2 = random(0,100);
111+
number3 = random(0,100);
112+
number4 = random(0,100);
113+
114+
delay(20000); // Wait 20 seconds to update the channel again
115+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Use this file to store all of the private credentials
2+
// and connection details
3+
4+
#define SECRET_SSID "MySSID" // replace MySSID with your WiFi network name
5+
#define SECRET_PASS "MyPassword" // replace MyPassword with your WiFi password
6+
7+
#define SECRET_CH_ID 000000 // replace 0000000 with your channel number
8+
#define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key

0 commit comments

Comments
 (0)