├── .gitignore ├── ESP-01_AT_Commands_Hardware_Serial_Hookup.pdf ├── ESP-01_AT_Commands_SoftSerial_Hookup.pdf ├── README.md ├── examples ├── ArduinoEthernet │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ └── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h ├── ArduinoMKR1000 │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── ReadFieldSecure │ │ ├── ReadFieldSecure.ino │ │ └── secrets.h │ ├── ReadMultipleFields │ │ ├── ReadMultipleFields.ino │ │ └── secrets.h │ ├── ReadMultipleFieldsSecure │ │ ├── ReadMultipleFieldsSecure.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ ├── WriteMultipleFieldsSecure │ │ ├── WriteMultipleFieldsSecure.ino │ │ └── secrets.h │ ├── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h │ └── WriteSingleFieldSecure │ │ ├── WriteSingleFieldSecure.ino │ │ └── secrets.h ├── ArduinoMKRETHShield │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ └── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h ├── ArduinoMKRGSM1400 │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ └── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h ├── ArduinoMKRVIDOR4000 │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ └── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h ├── ArduinoMKRWiFi1010 │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ └── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h ├── ArduinoUnoWiFi Rev2 │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ └── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h ├── ArduinoWiFiShield │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ └── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h ├── ArduinoWiFiShield101 │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ └── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h ├── ArduinoYun │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ └── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h ├── ESP32 │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── ReadFieldSecure │ │ ├── ReadFieldSecure.ino │ │ └── secrets.h │ ├── ReadMultipleFields │ │ ├── ReadMultipleFields.ino │ │ └── secrets.h │ ├── ReadMultipleFieldsSecure │ │ ├── ReadMultipleFieldsSecure.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ ├── WriteMultipleFieldsSecure │ │ ├── WriteMultipleFieldsSecure.ino │ │ └── secrets.h │ ├── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h │ └── WriteSingleFieldSecure │ │ ├── WriteSingleFieldSecure.ino │ │ └── secrets.h └── ESP8266 │ ├── program board directly │ ├── ReadField │ │ ├── ReadField.ino │ │ └── secrets.h │ ├── ReadFieldSecure │ │ ├── ReadFieldSecure.ino │ │ └── secrets.h │ ├── ReadMultipleFields │ │ ├── ReadMultipleFields.ino │ │ └── secrets.h │ ├── ReadMultipleFieldsSecure │ │ ├── ReadMultipleFieldsSecure.ino │ │ └── secrets.h │ ├── WriteMultipleFields │ │ ├── WriteMultipleFields.ino │ │ └── secrets.h │ ├── WriteMultipleFieldsSecure │ │ ├── WriteMultipleFieldsSecure.ino │ │ └── secrets.h │ ├── WriteSingleField │ │ ├── WriteSingleField.ino │ │ └── secrets.h │ └── WriteSingleFieldSecure │ │ ├── WriteSingleFieldSecure.ino │ │ └── secrets.h │ └── via AT commands │ ├── ReadField │ ├── ReadField.ino │ └── secrets.h │ ├── WriteMultipleFields │ ├── WriteMultipleFields.ino │ └── secrets.h │ └── WriteSingleField │ ├── WriteSingleField.ino │ └── secrets.h ├── extras └── test │ ├── testBegin │ └── testBegin.ino │ ├── testReadField │ └── testReadField.ino │ ├── testReadMultiple │ └── testReadMultiple.ino │ ├── testSecureConnect │ └── testSecureConnect.ino │ ├── testSetFunctions │ └── testSetFunctions.ino │ └── testWriteField │ └── testWriteField.ino ├── keywords.txt ├── library.properties ├── license.md └── src ├── ThingSpeak.cpp └── ThingSpeak.h /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /ESP-01_AT_Commands_Hardware_Serial_Hookup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/thingspeak-arduino/73ab8c819f3f16dda82e94e650cd07188c8898a3/ESP-01_AT_Commands_Hardware_Serial_Hookup.pdf -------------------------------------------------------------------------------- /ESP-01_AT_Commands_SoftSerial_Hookup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mathworks/thingspeak-arduino/73ab8c819f3f16dda82e94e650cd07188c8898a3/ESP-01_AT_Commands_SoftSerial_Hookup.pdf -------------------------------------------------------------------------------- /examples/ArduinoEthernet/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ReadField 3 | 4 | Description: Demonstates reading from a public channel which doesn't not require an API key and reading from a private channel which does 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 Ethernet 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires the Ethernet library 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #include 27 | #include "secrets.h" 28 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 29 | 30 | byte mac[] = SECRET_MAC; 31 | 32 | // Set the static IP address to use if the DHCP fails to assign 33 | IPAddress ip(192, 168, 0, 177); 34 | IPAddress myDns(192, 168, 0, 1); 35 | 36 | EthernetClient client; 37 | 38 | // Weather station channel details 39 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 40 | unsigned int temperatureFieldNumber = 4; 41 | 42 | // Counting channel details 43 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 44 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 45 | unsigned int counterFieldNumber = 1; 46 | 47 | void setup() { 48 | Ethernet.init(10); // Most Arduino Ethernet hardware 49 | Serial.begin(115200); //Initialize serial 50 | while (!Serial) { 51 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 52 | } 53 | 54 | // start the Ethernet connection: 55 | Serial.println("Initialize Ethernet with DHCP:"); 56 | if (Ethernet.begin(mac) == 0) { 57 | Serial.println("Failed to configure Ethernet using DHCP"); 58 | // Check for Ethernet hardware present 59 | if (Ethernet.hardwareStatus() == EthernetNoHardware) { 60 | Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); 61 | while (true) { 62 | delay(1); // do nothing, no point running without Ethernet hardware 63 | } 64 | } 65 | if (Ethernet.linkStatus() == LinkOFF) { 66 | Serial.println("Ethernet cable is not connected."); 67 | } 68 | // try to congifure using IP address instead of DHCP: 69 | Ethernet.begin(mac, ip, myDns); 70 | } else { 71 | Serial.print(" DHCP assigned IP "); 72 | Serial.println(Ethernet.localIP()); 73 | } 74 | // give the Ethernet shield a second to initialize: 75 | delay(1000); 76 | 77 | ThingSpeak.begin(client); // Initialize ThingSpeak 78 | } 79 | 80 | void loop() { 81 | 82 | int statusCode = 0; 83 | 84 | // Read in field 4 of the public channel recording the temperature 85 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 86 | 87 | // Check the status of the read operation to see if it was successful 88 | statusCode = ThingSpeak.getLastReadStatus(); 89 | if(statusCode == 200){ 90 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 91 | } 92 | else{ 93 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 94 | } 95 | 96 | delay(15000); // No need to read the temperature too often. 97 | 98 | // Read in field 1 of the private channel which is a counter 99 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 100 | 101 | // Check the status of the read operation to see if it was successful 102 | statusCode = ThingSpeak.getLastReadStatus(); 103 | if(statusCode == 200){ 104 | Serial.println("Counter: " + String(count)); 105 | } 106 | else{ 107 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 108 | } 109 | 110 | delay(15000); // No need to read the counter too often. 111 | 112 | } 113 | -------------------------------------------------------------------------------- /examples/ArduinoEthernet/ReadField/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | // Enter a MAC address for your controller below. 5 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 6 | #define SECRET_MAC {0x90, 0xA2, 0xDA, 0x10, 0x40, 0x4F} 7 | 8 | #define SECRET_CH_ID_WEATHER_STATION 12397 //MathWorks weather station 9 | 10 | #define SECRET_CH_ID_COUNTER 298725 //Test channel for counting 11 | #define SECRET_READ_APIKEY_COUNTER "SODG0O2UZVGKWAWG" //API Key for Test channel 12 | -------------------------------------------------------------------------------- /examples/ArduinoEthernet/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteMultipleFields 3 | 4 | Description: Writes values to fields 1,2,3 and 4 in a single ThingSpeak update every 20 seconds. 5 | 6 | Hardware: Arduino Ethernet 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires the Ethernet library 12 | 13 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 14 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 15 | 16 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 17 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 18 | 19 | For licensing information, see the accompanying license file. 20 | 21 | Copyright 2020, The MathWorks, Inc. 22 | */ 23 | 24 | #include 25 | #include "secrets.h" 26 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 27 | 28 | byte mac[] = SECRET_MAC; 29 | 30 | // Set the static IP address to use if the DHCP fails to assign 31 | IPAddress ip(192, 168, 0, 177); 32 | IPAddress myDns(192, 168, 0, 1); 33 | 34 | EthernetClient client; 35 | 36 | unsigned long myChannelNumber = SECRET_CH_ID; 37 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 38 | 39 | // Initialize our values 40 | int number1 = 0; 41 | int number2 = random(0,100); 42 | int number3 = random(0,100); 43 | int number4 = random(0,100); 44 | 45 | void setup() { 46 | Ethernet.init(10); // Most Arduino Ethernet hardware 47 | Serial.begin(115200); //Initialize serial 48 | while (!Serial) { 49 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 50 | } 51 | 52 | // start the Ethernet connection: 53 | Serial.println("Initialize Ethernet with DHCP:"); 54 | if (Ethernet.begin(mac) == 0) { 55 | Serial.println("Failed to configure Ethernet using DHCP"); 56 | // Check for Ethernet hardware present 57 | if (Ethernet.hardwareStatus() == EthernetNoHardware) { 58 | Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); 59 | while (true) { 60 | delay(1); // do nothing, no point running without Ethernet hardware 61 | } 62 | } 63 | if (Ethernet.linkStatus() == LinkOFF) { 64 | Serial.println("Ethernet cable is not connected."); 65 | } 66 | // try to congifure using IP address instead of DHCP: 67 | Ethernet.begin(mac, ip, myDns); 68 | } else { 69 | Serial.print(" DHCP assigned IP "); 70 | Serial.println(Ethernet.localIP()); 71 | } 72 | // give the Ethernet shield a second to initialize: 73 | delay(1000); 74 | 75 | ThingSpeak.begin(client); // Initialize ThingSpeak 76 | } 77 | 78 | void loop() { 79 | 80 | // set the fields with the values 81 | ThingSpeak.setField(1, number1); 82 | ThingSpeak.setField(2, number2); 83 | ThingSpeak.setField(3, number3); 84 | ThingSpeak.setField(4, number4); 85 | 86 | 87 | // write to the ThingSpeak channel 88 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 89 | if(x == 200){ 90 | Serial.println("Channel update successful."); 91 | } 92 | else{ 93 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 94 | } 95 | 96 | // change the values 97 | number1++; 98 | if(number1 > 99){ 99 | number1 = 0; 100 | } 101 | number2 = random(0,100); 102 | number3 = random(0,100); 103 | number4 = random(0,100); 104 | 105 | delay(20000); // Wait 20 seconds to update the channel again 106 | } 107 | -------------------------------------------------------------------------------- /examples/ArduinoEthernet/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | // Enter a MAC address for your controller below. 5 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 6 | #define SECRET_MAC {0x90, 0xA2, 0xDA, 0x10, 0x40, 0x4F} 7 | 8 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 9 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 10 | -------------------------------------------------------------------------------- /examples/ArduinoEthernet/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: Arduino Ethernet 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires the Ethernet library 12 | 13 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 14 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 15 | 16 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 17 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 18 | 19 | For licensing information, see the accompanying license file. 20 | 21 | Copyright 2020, The MathWorks, Inc. 22 | */ 23 | 24 | #include 25 | #include "secrets.h" 26 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 27 | 28 | byte mac[] = SECRET_MAC; 29 | 30 | // Set the static IP address to use if the DHCP fails to assign 31 | IPAddress ip(192, 168, 0, 177); 32 | IPAddress myDns(192, 168, 0, 1); 33 | 34 | EthernetClient client; 35 | 36 | unsigned long myChannelNumber = SECRET_CH_ID; 37 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 38 | 39 | int number = 0; 40 | 41 | void setup() { 42 | Ethernet.init(10); // Most Arduino Ethernet hardware 43 | Serial.begin(115200); //Initialize serial 44 | while (!Serial) { 45 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 46 | } 47 | 48 | // start the Ethernet connection: 49 | Serial.println("Initialize Ethernet with DHCP:"); 50 | if (Ethernet.begin(mac) == 0) { 51 | Serial.println("Failed to configure Ethernet using DHCP"); 52 | // Check for Ethernet hardware present 53 | if (Ethernet.hardwareStatus() == EthernetNoHardware) { 54 | Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); 55 | while (true) { 56 | delay(1); // do nothing, no point running without Ethernet hardware 57 | } 58 | } 59 | if (Ethernet.linkStatus() == LinkOFF) { 60 | Serial.println("Ethernet cable is not connected."); 61 | } 62 | // try to congifure using IP address instead of DHCP: 63 | Ethernet.begin(mac, ip, myDns); 64 | } else { 65 | Serial.print(" DHCP assigned IP "); 66 | Serial.println(Ethernet.localIP()); 67 | } 68 | // give the Ethernet shield a second to initialize: 69 | delay(1000); 70 | 71 | ThingSpeak.begin(client); // Initialize ThingSpeak 72 | } 73 | 74 | void loop() { 75 | 76 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 77 | // pieces of information in a channel. Here, we write to field 1. 78 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 79 | if(x == 200){ 80 | Serial.println("Channel update successful."); 81 | } 82 | else{ 83 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 84 | } 85 | 86 | // change the value 87 | number++; 88 | if(number > 99){ 89 | number = 0; 90 | } 91 | 92 | delay(20000); // Wait 20 seconds to update the channel again 93 | } 94 | -------------------------------------------------------------------------------- /examples/ArduinoEthernet/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | // Enter a MAC address for your controller below. 5 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 6 | #define SECRET_MAC {0x90, 0xA2, 0xDA, 0x10, 0x40, 0x4F} 7 | 8 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 9 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 10 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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 MKR1000 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires WiFi101 library version 0.15.3 or newer. 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 2020, The MathWorks, Inc. 25 | */ 26 | 27 | #include 28 | #include "secrets.h" 29 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 49 | } 50 | ThingSpeak.begin(client); // Initialize ThingSpeak 51 | } 52 | 53 | void loop() { 54 | 55 | int statusCode = 0; 56 | 57 | // Connect or reconnect to WiFi 58 | if(WiFi.status() != WL_CONNECTED){ 59 | Serial.print("Attempting to connect to SSID: "); 60 | Serial.println(SECRET_SSID); 61 | while(WiFi.status() != WL_CONNECTED){ 62 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 63 | Serial.print("."); 64 | delay(5000); 65 | } 66 | Serial.println("\nConnected"); 67 | } 68 | 69 | // Read in field 4 of the public channel recording the temperature 70 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 71 | 72 | // Check the status of the read operation to see if it was successful 73 | statusCode = ThingSpeak.getLastReadStatus(); 74 | if(statusCode == 200){ 75 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 76 | } 77 | else{ 78 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 79 | } 80 | 81 | delay(15000); // No need to read the temperature too often. 82 | 83 | // Read in field 1 of the private channel which is a counter 84 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 85 | 86 | // Check the status of the read operation to see if it was successful 87 | statusCode = ThingSpeak.getLastReadStatus(); 88 | if(statusCode == 200){ 89 | Serial.println("Counter: " + String(count)); 90 | } 91 | else{ 92 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 93 | } 94 | 95 | delay(15000); // No need to read the counter too often. 96 | 97 | } 98 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/ReadField/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/ReadFieldSecure/ReadFieldSecure.ino: -------------------------------------------------------------------------------- 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 over secured HTTPS connection. 7 | 8 | Hardware: Arduino MKR1000 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires WiFi101 library version 0.15.3 or newer. 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 2020, The MathWorks, Inc. 25 | */ 26 | 27 | #define TS_ENABLE_SSL // For HTTPS SSL connection 28 | 29 | #include 30 | #include "secrets.h" 31 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 32 | 33 | char ssid[] = SECRET_SSID; // your network SSID (name) 34 | char pass[] = SECRET_PASS; // your network password 35 | int keyIndex = 0; // your network key Index number (needed only for WEP) 36 | WiFiSSLClient client; 37 | 38 | // Weather station channel details 39 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 40 | unsigned int temperatureFieldNumber = 4; 41 | 42 | // Counting channel details 43 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 44 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 45 | unsigned int counterFieldNumber = 1; 46 | 47 | void setup() { 48 | Serial.begin(115200); // Initialize serial 49 | while (!Serial) { 50 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 51 | } 52 | 53 | ThingSpeak.begin(client); // Initialize ThingSpeak 54 | } 55 | 56 | void loop() { 57 | 58 | int statusCode = 0; 59 | 60 | // Connect or reconnect to WiFi 61 | if(WiFi.status() != WL_CONNECTED){ 62 | Serial.print("Attempting to connect to SSID: "); 63 | Serial.println(SECRET_SSID); 64 | while(WiFi.status() != WL_CONNECTED){ 65 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 66 | Serial.print("."); 67 | delay(5000); 68 | } 69 | Serial.println("\nConnected"); 70 | } 71 | 72 | // Read in field 4 of the public channel recording the temperature 73 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 74 | 75 | // Check the status of the read operation to see if it was successful 76 | statusCode = ThingSpeak.getLastReadStatus(); 77 | if(statusCode == 200){ 78 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 79 | } 80 | else{ 81 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 82 | } 83 | 84 | delay(15000); // No need to read the temperature too often. 85 | 86 | // Read in field 1 of the private channel which is a counter 87 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 88 | 89 | // Check the status of the read operation to see if it was successful 90 | statusCode = ThingSpeak.getLastReadStatus(); 91 | if(statusCode == 200){ 92 | Serial.println("Counter: " + String(count)); 93 | } 94 | else{ 95 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 96 | } 97 | 98 | delay(15000); // No need to read the counter too often. 99 | 100 | } 101 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/ReadFieldSecure/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/ReadMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/ReadMultipleFieldsSecure/secrets.h: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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 MKR1000 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires WiFi101 library version 0.15.3 or newer. 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | while (!Serial) { 47 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 48 | } 49 | 50 | ThingSpeak.begin(client); // Initialize ThingSpeak 51 | } 52 | 53 | void loop() { 54 | 55 | // Connect or reconnect to WiFi 56 | if(WiFi.status() != WL_CONNECTED){ 57 | Serial.print("Attempting to connect to SSID: "); 58 | Serial.println(SECRET_SSID); 59 | while(WiFi.status() != WL_CONNECTED){ 60 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 61 | Serial.print("."); 62 | delay(5000); 63 | } 64 | Serial.println("\nConnected."); 65 | } 66 | 67 | // set the fields with the values 68 | ThingSpeak.setField(1, number1); 69 | ThingSpeak.setField(2, number2); 70 | ThingSpeak.setField(3, number3); 71 | ThingSpeak.setField(4, number4); 72 | 73 | // figure out the status message 74 | if(number1 > number2){ 75 | myStatus = String("field1 is greater than field2"); 76 | } 77 | else if(number1 < number2){ 78 | myStatus = String("field1 is less than field2"); 79 | } 80 | else{ 81 | myStatus = String("field1 equals field2"); 82 | } 83 | 84 | // set the status 85 | ThingSpeak.setStatus(myStatus); 86 | 87 | // write to the ThingSpeak channel 88 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 89 | if(x == 200){ 90 | Serial.println("Channel update successful."); 91 | } 92 | else{ 93 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 94 | } 95 | 96 | // change the values 97 | number1++; 98 | if(number1 > 99){ 99 | number1 = 0; 100 | } 101 | number2 = random(0,100); 102 | number3 = random(0,100); 103 | number4 = random(0,100); 104 | 105 | delay(20000); // Wait 20 seconds to update the channel again 106 | } 107 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/WriteMultipleFieldsSecure/WriteMultipleFieldsSecure.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteMultipleFields 3 | 4 | Description: Writes values to fields 1,2,3,4 and status in a single ThingSpeak update every 20 seconds over secured HTTPS connection. 5 | 6 | Hardware: Arduino MKR1000 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires WiFi101 library version 0.15.3 or newer. 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #define TS_ENABLE_SSL // For HTTPS SSL connection 26 | 27 | #include 28 | #include "secrets.h" 29 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | WiFiSSLClient client; 35 | 36 | unsigned long myChannelNumber = SECRET_CH_ID; 37 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 38 | 39 | // Initialize our values 40 | int number1 = 0; 41 | int number2 = random(0,100); 42 | int number3 = random(0,100); 43 | int number4 = random(0,100); 44 | String myStatus = ""; 45 | 46 | void setup() { 47 | Serial.begin(115200); // Initialize serial 48 | while (!Serial) { 49 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 50 | } 51 | 52 | ThingSpeak.begin(client); // Initialize ThingSpeak 53 | } 54 | 55 | void loop() { 56 | 57 | // Connect or reconnect to WiFi 58 | if(WiFi.status() != WL_CONNECTED){ 59 | Serial.print("Attempting to connect to SSID: "); 60 | Serial.println(SECRET_SSID); 61 | while(WiFi.status() != WL_CONNECTED){ 62 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 63 | Serial.print("."); 64 | delay(5000); 65 | } 66 | Serial.println("\nConnected."); 67 | } 68 | 69 | // set the fields with the values 70 | ThingSpeak.setField(1, number1); 71 | ThingSpeak.setField(2, number2); 72 | ThingSpeak.setField(3, number3); 73 | ThingSpeak.setField(4, number4); 74 | 75 | // figure out the status message 76 | if(number1 > number2){ 77 | myStatus = String("field1 is greater than field2"); 78 | } 79 | else if(number1 < number2){ 80 | myStatus = String("field1 is less than field2"); 81 | } 82 | else{ 83 | myStatus = String("field1 equals field2"); 84 | } 85 | 86 | // set the status 87 | ThingSpeak.setStatus(myStatus); 88 | 89 | // write to the ThingSpeak channel 90 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 91 | if(x == 200){ 92 | Serial.println("Channel update successful."); 93 | } 94 | else{ 95 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 96 | } 97 | 98 | // change the values 99 | number1++; 100 | if(number1 > 99){ 101 | number1 = 0; 102 | } 103 | number2 = random(0,100); 104 | number3 = random(0,100); 105 | number4 = random(0,100); 106 | 107 | delay(20000); // Wait 20 seconds to update the channel again 108 | } 109 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/WriteMultipleFieldsSecure/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: Arduino MKR1000 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires WiFi101 library version 0.15.3 or newer. 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | int number = 0; 38 | 39 | void setup() { 40 | Serial.begin(115200); // Initialize serial 41 | while (!Serial) { 42 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 43 | } 44 | 45 | ThingSpeak.begin(client); // Initialize ThingSpeak 46 | } 47 | 48 | void loop() { 49 | 50 | // Connect or reconnect to WiFi 51 | if(WiFi.status() != WL_CONNECTED){ 52 | Serial.print("Attempting to connect to SSID: "); 53 | Serial.println(SECRET_SSID); 54 | while(WiFi.status() != WL_CONNECTED){ 55 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 56 | Serial.print("."); 57 | delay(5000); 58 | } 59 | Serial.println("\nConnected."); 60 | } 61 | 62 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 63 | // pieces of information in a channel. Here, we write to field 1. 64 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 65 | if(x == 200){ 66 | Serial.println("Channel update successful."); 67 | } 68 | else{ 69 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 70 | } 71 | 72 | // change the value 73 | number++; 74 | if(number > 99){ 75 | number = 0; 76 | } 77 | 78 | delay(20000); // Wait 20 seconds to update the channel again 79 | } 80 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/WriteSingleFieldSecure/WriteSingleFieldSecure.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds over secured HTTPS connection. 5 | 6 | Hardware: Arduino MKR1000 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires WiFi101 library version 0.15.3 or newer. 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #define TS_ENABLE_SSL // For HTTPS SSL connection 26 | 27 | #include 28 | #include "secrets.h" 29 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | WiFiSSLClient client; 35 | 36 | unsigned long myChannelNumber = SECRET_CH_ID; 37 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 38 | 39 | int number = 0; 40 | 41 | void setup() { 42 | Serial.begin(115200); // Initialize serial 43 | while (!Serial) { 44 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 45 | } 46 | 47 | ThingSpeak.begin(client); // Initialize ThingSpeak 48 | } 49 | 50 | void loop() { 51 | 52 | // Connect or reconnect to WiFi 53 | if(WiFi.status() != WL_CONNECTED){ 54 | Serial.print("Attempting to connect to SSID: "); 55 | Serial.println(SECRET_SSID); 56 | while(WiFi.status() != WL_CONNECTED){ 57 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 58 | Serial.print("."); 59 | delay(5000); 60 | } 61 | Serial.println("\nConnected."); 62 | } 63 | 64 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 65 | // pieces of information in a channel. Here, we write to field 1. 66 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 67 | if(x == 200){ 68 | Serial.println("Channel update successful."); 69 | } 70 | else{ 71 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 72 | } 73 | 74 | // change the value 75 | number++; 76 | if(number > 99){ 77 | number = 0; 78 | } 79 | 80 | delay(20000); // Wait 20 seconds to update the channel again 81 | } 82 | -------------------------------------------------------------------------------- /examples/ArduinoMKR1000/WriteSingleFieldSecure/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoMKRETHShield/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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 MKR ETH Shield 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires the Ethernet library 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #include 27 | #include "secrets.h" 28 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 29 | 30 | byte mac[] = SECRET_MAC; 31 | 32 | // Set the static IP address to use if the DHCP fails to assign 33 | IPAddress ip(192, 168, 0, 177); 34 | IPAddress myDns(192, 168, 0, 1); 35 | 36 | EthernetClient client; 37 | 38 | // Weather station channel details 39 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 40 | unsigned int temperatureFieldNumber = 4; 41 | 42 | // Counting channel details 43 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 44 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 45 | unsigned int counterFieldNumber = 1; 46 | 47 | void setup() { 48 | Ethernet.init(5); // MKR ETH shield 49 | Serial.begin(115200); //Initialize serial 50 | while (!Serial) { 51 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 52 | } 53 | 54 | // start the Ethernet connection: 55 | Serial.println("Initialize Ethernet with DHCP:"); 56 | if (Ethernet.begin(mac) == 0) { 57 | Serial.println("Failed to configure Ethernet using DHCP"); 58 | // Check for Ethernet hardware present 59 | if (Ethernet.hardwareStatus() == EthernetNoHardware) { 60 | Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); 61 | while (true) { 62 | delay(1); // do nothing, no point running without Ethernet hardware 63 | } 64 | } 65 | if (Ethernet.linkStatus() == LinkOFF) { 66 | Serial.println("Ethernet cable is not connected."); 67 | } 68 | // try to congifure using IP address instead of DHCP: 69 | Ethernet.begin(mac, ip, myDns); 70 | } else { 71 | Serial.print(" DHCP assigned IP "); 72 | Serial.println(Ethernet.localIP()); 73 | } 74 | // give the Ethernet shield a second to initialize: 75 | delay(1000); 76 | 77 | ThingSpeak.begin(client); // Initialize ThingSpeak 78 | } 79 | 80 | void loop() { 81 | 82 | int statusCode = 0; 83 | 84 | // Read in field 4 of the public channel recording the temperature 85 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 86 | 87 | // Check the status of the read operation to see if it was successful 88 | statusCode = ThingSpeak.getLastReadStatus(); 89 | if(statusCode == 200){ 90 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 91 | } 92 | else{ 93 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 94 | } 95 | 96 | delay(15000); // No need to read the temperature too often. 97 | 98 | // Read in field 1 of the private channel which is a counter 99 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 100 | 101 | // Check the status of the read operation to see if it was successful 102 | statusCode = ThingSpeak.getLastReadStatus(); 103 | if(statusCode == 200){ 104 | Serial.println("Counter: " + String(count)); 105 | } 106 | else{ 107 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 108 | } 109 | 110 | delay(15000); // No need to read the counter too often. 111 | 112 | } 113 | -------------------------------------------------------------------------------- /examples/ArduinoMKRETHShield/ReadField/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | // Enter a MAC address for your controller below. 5 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 6 | #define SECRET_MAC {0x90, 0xA2, 0xDA, 0x10, 0x40, 0x4F} 7 | 8 | #define SECRET_CH_ID_WEATHER_STATION 12397 //MathWorks weather station 9 | 10 | #define SECRET_CH_ID_COUNTER 298725 //Test channel for counting 11 | #define SECRET_READ_APIKEY_COUNTER "SODG0O2UZVGKWAWG" //API Key for Test channel 12 | -------------------------------------------------------------------------------- /examples/ArduinoMKRETHShield/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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 MKR ETH Shield 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires the Ethernet library 12 | 13 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 14 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 15 | 16 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 17 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 18 | 19 | For licensing information, see the accompanying license file. 20 | 21 | Copyright 2020, The MathWorks, Inc. 22 | */ 23 | 24 | #include 25 | #include "secrets.h" 26 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 27 | 28 | byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x40, 0x4F }; 29 | 30 | // Set the static IP address to use if the DHCP fails to assign 31 | IPAddress ip(192, 168, 0, 177); 32 | IPAddress myDns(192, 168, 0, 1); 33 | 34 | EthernetClient client; 35 | 36 | unsigned long myChannelNumber = SECRET_CH_ID; 37 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 38 | 39 | // Initialize our values 40 | int number1 = 0; 41 | int number2 = random(0,100); 42 | int number3 = random(0,100); 43 | int number4 = random(0,100); 44 | String myStatus = ""; 45 | 46 | void setup() { 47 | Ethernet.init(5); // MKR ETH shield 48 | Serial.begin(115200); //Initialize serial 49 | while (!Serial) { 50 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 51 | } 52 | 53 | // start the Ethernet connection: 54 | Serial.println("Initialize Ethernet with DHCP:"); 55 | if (Ethernet.begin(mac) == 0) { 56 | Serial.println("Failed to configure Ethernet using DHCP"); 57 | // Check for Ethernet hardware present 58 | if (Ethernet.hardwareStatus() == EthernetNoHardware) { 59 | Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); 60 | while (true) { 61 | delay(1); // do nothing, no point running without Ethernet hardware 62 | } 63 | } 64 | if (Ethernet.linkStatus() == LinkOFF) { 65 | Serial.println("Ethernet cable is not connected."); 66 | } 67 | // try to congifure using IP address instead of DHCP: 68 | Ethernet.begin(mac, ip, myDns); 69 | } else { 70 | Serial.print(" DHCP assigned IP "); 71 | Serial.println(Ethernet.localIP()); 72 | } 73 | // give the Ethernet shield a second to initialize: 74 | delay(1000); 75 | 76 | ThingSpeak.begin(client); // Initialize ThingSpeak 77 | } 78 | 79 | void loop() { 80 | 81 | // set the fields with the values 82 | ThingSpeak.setField(1, number1); 83 | ThingSpeak.setField(2, number2); 84 | ThingSpeak.setField(3, number3); 85 | ThingSpeak.setField(4, number4); 86 | 87 | // figure out the status message 88 | if(number1 > number2){ 89 | myStatus = String("field1 is greater than field2"); 90 | } 91 | else if(number1 < number2){ 92 | myStatus = String("field1 is less than field2"); 93 | } 94 | else{ 95 | myStatus = String("field1 equals field2"); 96 | } 97 | 98 | // set the status 99 | ThingSpeak.setStatus(myStatus); 100 | 101 | // write to the ThingSpeak channel 102 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 103 | if(x == 200){ 104 | Serial.println("Channel update successful."); 105 | } 106 | else{ 107 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 108 | } 109 | 110 | // change the values 111 | number1++; 112 | if(number1 > 99){ 113 | number1 = 0; 114 | } 115 | number2 = random(0,100); 116 | number3 = random(0,100); 117 | number4 = random(0,100); 118 | 119 | delay(20000); // Wait 20 seconds to update the channel again 120 | } 121 | -------------------------------------------------------------------------------- /examples/ArduinoMKRETHShield/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | // Enter a MAC address for your controller below. 5 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 6 | #define SECRET_MAC {0x90, 0xA2, 0xDA, 0x10, 0x40, 0x4F} 7 | 8 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 9 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 10 | -------------------------------------------------------------------------------- /examples/ArduinoMKRETHShield/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: Arduino MKR ETH Shield 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires the Ethernet library 12 | 13 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 14 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 15 | 16 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 17 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 18 | 19 | For licensing information, see the accompanying license file. 20 | 21 | Copyright 2020, The MathWorks, Inc. 22 | */ 23 | 24 | #include 25 | #include "secrets.h" 26 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 27 | 28 | byte mac[] = { 0x90, 0xA2, 0xDA, 0x10, 0x40, 0x4F }; 29 | 30 | // Set the static IP address to use if the DHCP fails to assign 31 | IPAddress ip(192, 168, 0, 177); 32 | IPAddress myDns(192, 168, 0, 1); 33 | 34 | EthernetClient client; 35 | 36 | unsigned long myChannelNumber = SECRET_CH_ID; 37 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 38 | 39 | int number = 0; 40 | 41 | void setup() { 42 | Ethernet.init(5); // MKR ETH shield 43 | Serial.begin(115200); //Initialize serial 44 | while (!Serial) { 45 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 46 | } 47 | 48 | // start the Ethernet connection: 49 | Serial.println("Initialize Ethernet with DHCP:"); 50 | if (Ethernet.begin(mac) == 0) { 51 | Serial.println("Failed to configure Ethernet using DHCP"); 52 | // Check for Ethernet hardware present 53 | if (Ethernet.hardwareStatus() == EthernetNoHardware) { 54 | Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); 55 | while (true) { 56 | delay(1); // do nothing, no point running without Ethernet hardware 57 | } 58 | } 59 | if (Ethernet.linkStatus() == LinkOFF) { 60 | Serial.println("Ethernet cable is not connected."); 61 | } 62 | // try to congifure using IP address instead of DHCP: 63 | Ethernet.begin(mac, ip, myDns); 64 | } else { 65 | Serial.print(" DHCP assigned IP "); 66 | Serial.println(Ethernet.localIP()); 67 | } 68 | // give the Ethernet shield a second to initialize: 69 | delay(1000); 70 | 71 | ThingSpeak.begin(client); // Initialize ThingSpeak 72 | } 73 | 74 | void loop() { 75 | 76 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 77 | // pieces of information in a channel. Here, we write to field 1. 78 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 79 | if(x == 200){ 80 | Serial.println("Channel update successful."); 81 | } 82 | else{ 83 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 84 | } 85 | 86 | // change the value 87 | number++; 88 | if(number > 99){ 89 | number = 0; 90 | } 91 | 92 | delay(20000); // Wait 20 seconds to update the channel again 93 | } 94 | -------------------------------------------------------------------------------- /examples/ArduinoMKRETHShield/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | // Enter a MAC address for your controller below. 5 | // Newer Ethernet shields have a MAC address printed on a sticker on the shield 6 | #define SECRET_MAC {0x90, 0xA2, 0xDA, 0x10, 0x40, 0x4F} 7 | 8 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 9 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 10 | -------------------------------------------------------------------------------- /examples/ArduinoMKRGSM1400/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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 MKR GSM 1400 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires MKRGSM library. 14 | - Reqires GSM access (SIM card or credentials). 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 2020, The MathWorks, Inc. 25 | */ 26 | 27 | #include 28 | #include "secrets.h" 29 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 30 | 31 | // PIN Number 32 | const char PINNUMBER[] = SECRET_PIN; 33 | // APN data 34 | const char GPRS_APN[] = SECRET_GPRS_APN; 35 | const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; 36 | const char GPRS_PASSWORD[] = SECRET_GPRS_PASS; 37 | 38 | GSMClient client; 39 | GPRS gprs; 40 | GSM gsmAccess; 41 | 42 | // Weather station channel details 43 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 44 | unsigned int temperatureFieldNumber = 4; 45 | 46 | // Counting channel details 47 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 48 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 49 | unsigned int counterFieldNumber = 1; 50 | 51 | void setup() { 52 | Serial.begin(115200); //Initialize serial 53 | while (!Serial) { 54 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 55 | } 56 | 57 | Serial.println("Starting Arduino web client."); 58 | boolean connected = false; 59 | 60 | // wait 10 seconds for connection: 61 | delay(10000); 62 | 63 | while (!connected) { 64 | if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && 65 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { 66 | connected = true; 67 | } else { 68 | Serial.println("Not connected"); 69 | delay(1000); 70 | } 71 | } 72 | 73 | Serial.println("connected"); 74 | 75 | ThingSpeak.begin(client); // Initialize ThingSpeak 76 | } 77 | 78 | void loop() { 79 | 80 | int statusCode = 0; 81 | 82 | // Read in field 4 of the public channel recording the temperature 83 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 84 | 85 | // Check the status of the read operation to see if it was successful 86 | statusCode = ThingSpeak.getLastReadStatus(); 87 | if(statusCode == 200){ 88 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 89 | } 90 | else{ 91 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 92 | } 93 | 94 | delay(15000); // No need to read the temperature too often. 95 | 96 | // Read in field 1 of the private channel which is a counter 97 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 98 | 99 | // Check the status of the read operation to see if it was successful 100 | statusCode = ThingSpeak.getLastReadStatus(); 101 | if(statusCode == 200){ 102 | Serial.println("Counter: " + String(count)); 103 | } 104 | else{ 105 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 106 | } 107 | 108 | delay(15000); // No need to read the counter too often. 109 | 110 | } 111 | -------------------------------------------------------------------------------- /examples/ArduinoMKRGSM1400/ReadField/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | #define SECRET_PIN "" 5 | #define SECRET_GPRS_APN "GPRS_APN" 6 | #define SECRET_GPRS_LOGIN "login" 7 | #define SECRET_GPRS_PASS "password" 8 | 9 | #define SECRET_CH_ID_WEATHER_STATION 12397 //MathWorks weather station 10 | 11 | #define SECRET_CH_ID_COUNTER 298725 //Test channel for counting 12 | #define SECRET_READ_APIKEY_COUNTER "SODG0O2UZVGKWAWG" //API Key for Test channel 13 | -------------------------------------------------------------------------------- /examples/ArduinoMKRGSM1400/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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 MKR GSM 1400 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires MKRGSM library. 12 | - Reqires GSM access (SIM card or credentials). 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 28 | 29 | // PIN Number 30 | const char PINNUMBER[] = SECRET_PIN; 31 | // APN data 32 | const char GPRS_APN[] = SECRET_GPRS_APN; 33 | const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; 34 | const char GPRS_PASSWORD[] = SECRET_GPRS_PASS; 35 | 36 | GSMClient client; 37 | GPRS gprs; 38 | GSM gsmAccess; 39 | 40 | unsigned long myChannelNumber = SECRET_CH_ID; 41 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 42 | 43 | // Initialize our values 44 | int number1 = 0; 45 | int number2 = random(0,100); 46 | int number3 = random(0,100); 47 | int number4 = random(0,100); 48 | String myStatus = ""; 49 | 50 | void setup() { 51 | Serial.begin(115200); //Initialize serial 52 | while (!Serial) { 53 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 54 | } 55 | 56 | Serial.println("Starting Arduino web client."); 57 | boolean connected = false; 58 | 59 | // wait 10 seconds for connection: 60 | delay(10000); 61 | 62 | while (!connected) { 63 | if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && 64 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { 65 | connected = true; 66 | } else { 67 | Serial.println("Not connected"); 68 | delay(1000); 69 | } 70 | } 71 | 72 | Serial.println("connected"); 73 | 74 | ThingSpeak.begin(client); // Initialize ThingSpeak 75 | } 76 | 77 | void loop() { 78 | 79 | // set the fields with the values 80 | ThingSpeak.setField(1, number1); 81 | ThingSpeak.setField(2, number2); 82 | ThingSpeak.setField(3, number3); 83 | ThingSpeak.setField(4, number4); 84 | 85 | // figure out the status message 86 | if(number1 > number2){ 87 | myStatus = String("field1 is greater than field2"); 88 | } 89 | else if(number1 < number2){ 90 | myStatus = String("field1 is less than field2"); 91 | } 92 | else{ 93 | myStatus = String("field1 equals field2"); 94 | } 95 | 96 | // set the status 97 | ThingSpeak.setStatus(myStatus); 98 | 99 | // write to the ThingSpeak channel 100 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 101 | if(x == 200){ 102 | Serial.println("Channel update successful."); 103 | } 104 | else{ 105 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 106 | } 107 | 108 | // change the values 109 | number1++; 110 | if(number1 > 99){ 111 | number1 = 0; 112 | } 113 | number2 = random(0,100); 114 | number3 = random(0,100); 115 | number4 = random(0,100); 116 | 117 | delay(20000); // Wait 20 seconds to update the channel again 118 | } 119 | -------------------------------------------------------------------------------- /examples/ArduinoMKRGSM1400/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | #define SECRET_PIN "" 5 | #define SECRET_GPRS_APN "GPRS_APN" 6 | #define SECRET_GPRS_LOGIN "login" 7 | #define SECRET_GPRS_PASS "password" 8 | 9 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 10 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 11 | -------------------------------------------------------------------------------- /examples/ArduinoMKRGSM1400/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: Arduino MKR GSM 1400 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires MKRGSM library. 12 | - Reqires GSM access (SIM card or credentials). 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 28 | 29 | // PIN Number 30 | const char PINNUMBER[] = SECRET_PIN; 31 | // APN data 32 | const char GPRS_APN[] = SECRET_GPRS_APN; 33 | const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; 34 | const char GPRS_PASSWORD[] = SECRET_GPRS_PASS; 35 | 36 | GSMClient client; 37 | GPRS gprs; 38 | GSM gsmAccess; 39 | 40 | unsigned long myChannelNumber = SECRET_CH_ID; 41 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 42 | 43 | int number = 0; 44 | 45 | void setup() { 46 | Serial.begin(115200); //Initialize serial 47 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 49 | } 50 | 51 | Serial.println("Starting Arduino web client."); 52 | boolean connected = false; 53 | 54 | // wait 10 seconds for connection: 55 | delay(10000); 56 | 57 | while (!connected) { 58 | if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && 59 | (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { 60 | connected = true; 61 | } else { 62 | Serial.println("Not connected"); 63 | delay(1000); 64 | } 65 | } 66 | 67 | Serial.println("connected"); 68 | 69 | ThingSpeak.begin(client); // Initialize ThingSpeak 70 | } 71 | 72 | void loop() { 73 | 74 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 75 | // pieces of information in a channel. Here, we write to field 1. 76 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 77 | if(x == 200){ 78 | Serial.println("Channel update successful."); 79 | } 80 | else{ 81 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 82 | } 83 | 84 | // change the value 85 | number++; 86 | if(number > 99){ 87 | number = 0; 88 | } 89 | 90 | delay(20000); // Wait 20 seconds to update the channel again 91 | } 92 | -------------------------------------------------------------------------------- /examples/ArduinoMKRGSM1400/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | #define SECRET_PIN "" 5 | #define SECRET_GPRS_APN "GPRS_APN" 6 | #define SECRET_GPRS_LOGIN "login" 7 | #define SECRET_GPRS_PASS "password" 8 | 9 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 10 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 11 | -------------------------------------------------------------------------------- /examples/ArduinoMKRVIDOR4000/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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 MKR VIDOR 4000 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 2020, The MathWorks, Inc. 25 | */ 26 | 27 | #include 28 | #include "secrets.h" 29 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 49 | } 50 | 51 | // check for the WiFi module: 52 | if (WiFi.status() == WL_NO_MODULE) { 53 | Serial.println("Communication with WiFi module failed!"); 54 | // don't continue 55 | while (true); 56 | } 57 | 58 | String fv = WiFi.firmwareVersion(); 59 | if (fv != "1.0.0") { 60 | Serial.println("Please upgrade the firmware"); 61 | } 62 | 63 | ThingSpeak.begin(client); // Initialize ThingSpeak 64 | } 65 | 66 | void loop() { 67 | 68 | int statusCode = 0; 69 | 70 | // Connect or reconnect to WiFi 71 | if(WiFi.status() != WL_CONNECTED){ 72 | Serial.print("Attempting to connect to SSID: "); 73 | Serial.println(SECRET_SSID); 74 | while(WiFi.status() != WL_CONNECTED){ 75 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 76 | Serial.print("."); 77 | delay(5000); 78 | } 79 | Serial.println("\nConnected"); 80 | } 81 | 82 | // Read in field 4 of the public channel recording the temperature 83 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 84 | 85 | // Check the status of the read operation to see if it was successful 86 | statusCode = ThingSpeak.getLastReadStatus(); 87 | if(statusCode == 200){ 88 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 89 | } 90 | else{ 91 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 92 | } 93 | 94 | delay(15000); // No need to read the temperature too often. 95 | 96 | // Read in field 1 of the private channel which is a counter 97 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 98 | 99 | // Check the status of the read operation to see if it was successful 100 | statusCode = ThingSpeak.getLastReadStatus(); 101 | if(statusCode == 200){ 102 | Serial.println("Counter: " + String(count)); 103 | } 104 | else{ 105 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 106 | } 107 | 108 | delay(15000); // No need to read the counter too often. 109 | 110 | } 111 | -------------------------------------------------------------------------------- /examples/ArduinoMKRVIDOR4000/ReadField/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ArduinoMKRVIDOR4000/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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 MKR VIDOR 4000 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | while (!Serial) { 47 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 48 | } 49 | 50 | // check for the WiFi module: 51 | if (WiFi.status() == WL_NO_MODULE) { 52 | Serial.println("Communication with WiFi module failed!"); 53 | // don't continue 54 | while (true); 55 | } 56 | 57 | String fv = WiFi.firmwareVersion(); 58 | if (fv != "1.0.0") { 59 | Serial.println("Please upgrade the firmware"); 60 | } 61 | 62 | ThingSpeak.begin(client); // Initialize ThingSpeak 63 | } 64 | 65 | void loop() { 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 | // set the fields with the values 80 | ThingSpeak.setField(1, number1); 81 | ThingSpeak.setField(2, number2); 82 | ThingSpeak.setField(3, number3); 83 | ThingSpeak.setField(4, number4); 84 | 85 | // figure out the status message 86 | if(number1 > number2){ 87 | myStatus = String("field1 is greater than field2"); 88 | } 89 | else if(number1 < number2){ 90 | myStatus = String("field1 is less than field2"); 91 | } 92 | else{ 93 | myStatus = String("field1 equals field2"); 94 | } 95 | 96 | // set the status 97 | ThingSpeak.setStatus(myStatus); 98 | 99 | // write to the ThingSpeak channel 100 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 101 | if(x == 200){ 102 | Serial.println("Channel update successful."); 103 | } 104 | else{ 105 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 106 | } 107 | 108 | // change the values 109 | number1++; 110 | if(number1 > 99){ 111 | number1 = 0; 112 | } 113 | number2 = random(0,100); 114 | number3 = random(0,100); 115 | number4 = random(0,100); 116 | 117 | delay(20000); // ThingSpeak will only accept updates every 20 seconds. 118 | } 119 | -------------------------------------------------------------------------------- /examples/ArduinoMKRVIDOR4000/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoMKRVIDOR4000/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: Arduino MKR VIDOR 4000 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | int number = 0; 38 | 39 | void setup() { 40 | Serial.begin(115200); // Initialize serial 41 | while (!Serial) { 42 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 43 | } 44 | 45 | // check for the WiFi module: 46 | if (WiFi.status() == WL_NO_MODULE) { 47 | Serial.println("Communication with WiFi module failed!"); 48 | // don't continue 49 | while (true); 50 | } 51 | 52 | String fv = WiFi.firmwareVersion(); 53 | if (fv != "1.0.0") { 54 | Serial.println("Please upgrade the firmware"); 55 | } 56 | 57 | ThingSpeak.begin(client); // Initialize ThingSpeak 58 | } 59 | 60 | void loop() { 61 | 62 | // Connect or reconnect to WiFi 63 | if(WiFi.status() != WL_CONNECTED){ 64 | Serial.print("Attempting to connect to SSID: "); 65 | Serial.println(SECRET_SSID); 66 | while(WiFi.status() != WL_CONNECTED){ 67 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 68 | Serial.print("."); 69 | delay(5000); 70 | } 71 | Serial.println("\nConnected."); 72 | } 73 | 74 | 75 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 76 | // pieces of information in a channel. Here, we write to field 1. 77 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 78 | if(x == 200){ 79 | Serial.println("Channel update successful."); 80 | } 81 | else{ 82 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 83 | } 84 | 85 | // change the value 86 | number++; 87 | if(number > 99){ 88 | number = 0; 89 | } 90 | 91 | delay(20000); // ThingSpeak will only accept updates every 20 seconds. 92 | } 93 | -------------------------------------------------------------------------------- /examples/ArduinoMKRVIDOR4000/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoMKRWiFi1010/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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 MKR WiFi 1010 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 2020, The MathWorks, Inc. 25 | */ 26 | 27 | #include 28 | #include "secrets.h" 29 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 49 | } 50 | 51 | // check for the WiFi module: 52 | if (WiFi.status() == WL_NO_MODULE) { 53 | Serial.println("Communication with WiFi module failed!"); 54 | // don't continue 55 | while (true); 56 | } 57 | 58 | String fv = WiFi.firmwareVersion(); 59 | if (fv != "1.0.0") { 60 | Serial.println("Please upgrade the firmware"); 61 | } 62 | 63 | ThingSpeak.begin(client); //Initialize ThingSpeak 64 | } 65 | 66 | void loop() { 67 | 68 | int statusCode = 0; 69 | 70 | // Connect or reconnect to WiFi 71 | if(WiFi.status() != WL_CONNECTED){ 72 | Serial.print("Attempting to connect to SSID: "); 73 | Serial.println(SECRET_SSID); 74 | while(WiFi.status() != WL_CONNECTED){ 75 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 76 | Serial.print("."); 77 | delay(5000); 78 | } 79 | Serial.println("\nConnected"); 80 | } 81 | 82 | // Read in field 4 of the public channel recording the temperature 83 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 84 | 85 | // Check the status of the read operation to see if it was successful 86 | statusCode = ThingSpeak.getLastReadStatus(); 87 | if(statusCode == 200){ 88 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 89 | } 90 | else{ 91 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 92 | } 93 | 94 | delay(15000); // No need to read the temperature too often. 95 | 96 | // Read in field 1 of the private channel which is a counter 97 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 98 | 99 | // Check the status of the read operation to see if it was successful 100 | statusCode = ThingSpeak.getLastReadStatus(); 101 | if(statusCode == 200){ 102 | Serial.println("Counter: " + String(count)); 103 | } 104 | else{ 105 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 106 | } 107 | 108 | delay(15000); // No need to read the counter too often. 109 | 110 | } 111 | -------------------------------------------------------------------------------- /examples/ArduinoMKRWiFi1010/ReadField/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ArduinoMKRWiFi1010/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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 MKR WiFi 1010 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | while (!Serial) { 47 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 48 | } 49 | 50 | // check for the WiFi module: 51 | if (WiFi.status() == WL_NO_MODULE) { 52 | Serial.println("Communication with WiFi module failed!"); 53 | // don't continue 54 | while (true); 55 | } 56 | 57 | String fv = WiFi.firmwareVersion(); 58 | if (fv != "1.0.0") { 59 | Serial.println("Please upgrade the firmware"); 60 | } 61 | 62 | ThingSpeak.begin(client); //Initialize ThingSpeak 63 | } 64 | 65 | void loop() { 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 | // set the fields with the values 80 | ThingSpeak.setField(1, number1); 81 | ThingSpeak.setField(2, number2); 82 | ThingSpeak.setField(3, number3); 83 | ThingSpeak.setField(4, number4); 84 | 85 | // figure out the status message 86 | if(number1 > number2){ 87 | myStatus = String("field1 is greater than field2"); 88 | } 89 | else if(number1 < number2){ 90 | myStatus = String("field1 is less than field2"); 91 | } 92 | else{ 93 | myStatus = String("field1 equals field2"); 94 | } 95 | 96 | // set the status 97 | ThingSpeak.setStatus(myStatus); 98 | 99 | // write to the ThingSpeak channel 100 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 101 | if(x == 200){ 102 | Serial.println("Channel update successful."); 103 | } 104 | else{ 105 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 106 | } 107 | 108 | // change the values 109 | number1++; 110 | if(number1 > 99){ 111 | number1 = 0; 112 | } 113 | number2 = random(0,100); 114 | number3 = random(0,100); 115 | number4 = random(0,100); 116 | 117 | delay(20000); // Wait 20 seconds to update the channel again 118 | } 119 | -------------------------------------------------------------------------------- /examples/ArduinoMKRWiFi1010/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoMKRWiFi1010/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: Arduino MKR WiFi 1010 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | int number = 0; 38 | 39 | void setup() { 40 | Serial.begin(115200); // Initialize serial 41 | while (!Serial) { 42 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 43 | } 44 | 45 | // check for the WiFi module: 46 | if (WiFi.status() == WL_NO_MODULE) { 47 | Serial.println("Communication with WiFi module failed!"); 48 | // don't continue 49 | while (true); 50 | } 51 | 52 | String fv = WiFi.firmwareVersion(); 53 | if (fv != "1.0.0") { 54 | Serial.println("Please upgrade the firmware"); 55 | } 56 | 57 | ThingSpeak.begin(client); //Initialize ThingSpeak 58 | } 59 | 60 | void loop() { 61 | 62 | // Connect or reconnect to WiFi 63 | if(WiFi.status() != WL_CONNECTED){ 64 | Serial.print("Attempting to connect to SSID: "); 65 | Serial.println(SECRET_SSID); 66 | while(WiFi.status() != WL_CONNECTED){ 67 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 68 | Serial.print("."); 69 | delay(5000); 70 | } 71 | Serial.println("\nConnected."); 72 | } 73 | 74 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 75 | // pieces of information in a channel. Here, we write to field 1. 76 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 77 | if(x == 200){ 78 | Serial.println("Channel update successful."); 79 | } 80 | else{ 81 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 82 | } 83 | 84 | // change the value 85 | number++; 86 | if(number > 99){ 87 | number = 0; 88 | } 89 | 90 | delay(20000); // Wait 20 seconds to update the channel again 91 | } 92 | -------------------------------------------------------------------------------- /examples/ArduinoMKRWiFi1010/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoUnoWiFi Rev2/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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 2020, The MathWorks, Inc. 25 | */ 26 | 27 | #include 28 | #include "secrets.h" 29 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 49 | } 50 | 51 | // check for the WiFi module: 52 | if (WiFi.status() == WL_NO_MODULE) { 53 | Serial.println("Communication with WiFi module failed!"); 54 | // don't continue 55 | while (true); 56 | } 57 | 58 | String fv = WiFi.firmwareVersion(); 59 | if (fv != "1.0.0") { 60 | Serial.println("Please upgrade the firmware"); 61 | } 62 | 63 | ThingSpeak.begin(client); //Initialize ThingSpeak 64 | } 65 | 66 | void loop() { 67 | 68 | int statusCode = 0; 69 | 70 | // Connect or reconnect to WiFi 71 | if(WiFi.status() != WL_CONNECTED){ 72 | Serial.print("Attempting to connect to SSID: "); 73 | Serial.println(SECRET_SSID); 74 | while(WiFi.status() != WL_CONNECTED){ 75 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 76 | Serial.print("."); 77 | delay(5000); 78 | } 79 | Serial.println("\nConnected"); 80 | } 81 | 82 | // Read in field 4 of the public channel recording the temperature 83 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 84 | 85 | // Check the status of the read operation to see if it was successful 86 | statusCode = ThingSpeak.getLastReadStatus(); 87 | if(statusCode == 200){ 88 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 89 | } 90 | else{ 91 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 92 | } 93 | 94 | delay(15000); // No need to read the temperature too often. 95 | 96 | // Read in field 1 of the private channel which is a counter 97 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 98 | 99 | // Check the status of the read operation to see if it was successful 100 | statusCode = ThingSpeak.getLastReadStatus(); 101 | if(statusCode == 200){ 102 | Serial.println("Counter: " + String(count)); 103 | } 104 | else{ 105 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 106 | } 107 | 108 | delay(15000); // No need to read the counter too often. 109 | 110 | } 111 | -------------------------------------------------------------------------------- /examples/ArduinoUnoWiFi Rev2/ReadField/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ArduinoUnoWiFi Rev2/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | while (!Serial) { 47 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 48 | } 49 | 50 | // check for the WiFi module: 51 | if (WiFi.status() == WL_NO_MODULE) { 52 | Serial.println("Communication with WiFi module failed!"); 53 | // don't continue 54 | while (true); 55 | } 56 | 57 | String fv = WiFi.firmwareVersion(); 58 | if (fv != "1.0.0") { 59 | Serial.println("Please upgrade the firmware"); 60 | } 61 | 62 | ThingSpeak.begin(client); //Initialize ThingSpeak 63 | } 64 | 65 | void loop() { 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 | // set the fields with the values 80 | ThingSpeak.setField(1, number1); 81 | ThingSpeak.setField(2, number2); 82 | ThingSpeak.setField(3, number3); 83 | ThingSpeak.setField(4, number4); 84 | 85 | // figure out the status message 86 | if(number1 > number2){ 87 | myStatus = String("field1 is greater than field2"); 88 | } 89 | else if(number1 < number2){ 90 | myStatus = String("field1 is less than field2"); 91 | } 92 | else{ 93 | myStatus = String("field1 equals field2"); 94 | } 95 | 96 | // set the status 97 | ThingSpeak.setStatus(myStatus); 98 | 99 | // write to the ThingSpeak channel 100 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 101 | if(x == 200){ 102 | Serial.println("Channel update successful."); 103 | } 104 | else{ 105 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 106 | } 107 | 108 | // change the values 109 | number1++; 110 | if(number1 > 99){ 111 | number1 = 0; 112 | } 113 | number2 = random(0,100); 114 | number3 = random(0,100); 115 | number4 = random(0,100); 116 | 117 | delay(20000); // Wait 20 seconds to update the channel again 118 | } 119 | -------------------------------------------------------------------------------- /examples/ArduinoUnoWiFi Rev2/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoUnoWiFi Rev2/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak 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 2020, The MathWorks, Inc. 23 | */ 24 | 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | int number = 0; 38 | 39 | void setup() { 40 | Serial.begin(115200); // Initialize serial 41 | while (!Serial) { 42 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 43 | } 44 | 45 | // check for the WiFi module: 46 | if (WiFi.status() == WL_NO_MODULE) { 47 | Serial.println("Communication with WiFi module failed!"); 48 | // don't continue 49 | while (true); 50 | } 51 | 52 | String fv = WiFi.firmwareVersion(); 53 | if (fv != "1.0.0") { 54 | Serial.println("Please upgrade the firmware"); 55 | } 56 | 57 | ThingSpeak.begin(client); //Initialize ThingSpeak 58 | } 59 | 60 | void loop() { 61 | 62 | // Connect or reconnect to WiFi 63 | if(WiFi.status() != WL_CONNECTED){ 64 | Serial.print("Attempting to connect to SSID: "); 65 | Serial.println(SECRET_SSID); 66 | while(WiFi.status() != WL_CONNECTED){ 67 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 68 | Serial.print("."); 69 | delay(5000); 70 | } 71 | Serial.println("\nConnected."); 72 | } 73 | 74 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 75 | // pieces of information in a channel. Here, we write to field 1. 76 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 77 | if(x == 200){ 78 | Serial.println("Channel update successful."); 79 | } 80 | else{ 81 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 82 | } 83 | 84 | // change the value 85 | number++; 86 | if(number > 99){ 87 | number = 0; 88 | } 89 | 90 | delay(20000); // Wait 20 seconds to update the channel again 91 | } 92 | -------------------------------------------------------------------------------- /examples/ArduinoUnoWiFi Rev2/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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 WiFi Shield 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires the WiFi library 14 | - Ensure the WiFi Shield has the latest firmware. Instruction to update can be found here: https://www.arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading 15 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 16 | 17 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 18 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 19 | 20 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 21 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 22 | 23 | For licensing information, see the accompanying license file. 24 | 25 | Copyright 2020, The MathWorks, Inc. 26 | */ 27 | 28 | #include 29 | #include "secrets.h" 30 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 31 | 32 | char ssid[] = SECRET_SSID; // your network SSID (name) 33 | char pass[] = SECRET_PASS; // your network password 34 | int keyIndex = 0; // your network key Index number (needed only for WEP) 35 | WiFiClient client; 36 | 37 | // Weather station channel details 38 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 39 | unsigned int temperatureFieldNumber = 4; 40 | 41 | // Counting channel details 42 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 43 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 44 | unsigned int counterFieldNumber = 1; 45 | 46 | void setup() { 47 | //Initialize serial and wait for port to open: 48 | Serial.begin(115200); 49 | while (!Serial) { 50 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 51 | } 52 | 53 | // check for the presence of the shield: 54 | if (WiFi.status() == WL_NO_SHIELD) { 55 | Serial.println("WiFi shield not present"); 56 | // don't continue: 57 | while (true); 58 | } 59 | 60 | String fv = WiFi.firmwareVersion(); 61 | if (fv != "1.1.0") { 62 | Serial.println("Please upgrade the firmware"); 63 | } 64 | 65 | ThingSpeak.begin(client); // Initialize ThingSpeak 66 | } 67 | 68 | void loop() { 69 | 70 | int statusCode = 0; 71 | 72 | // Connect or reconnect to WiFi 73 | if(WiFi.status() != WL_CONNECTED){ 74 | Serial.print("Attempting to connect to SSID: "); 75 | Serial.println(SECRET_SSID); 76 | while(WiFi.status() != WL_CONNECTED){ 77 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 78 | Serial.print("."); 79 | delay(5000); 80 | } 81 | Serial.println("\nConnected"); 82 | } 83 | 84 | // Read in field 4 of the public channel recording the temperature 85 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 86 | 87 | // Check the status of the read operation to see if it was successful 88 | statusCode = ThingSpeak.getLastReadStatus(); 89 | if(statusCode == 200){ 90 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 91 | } 92 | else{ 93 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 94 | } 95 | 96 | delay(15000); // No need to read the temperature too often. 97 | 98 | // Read in field 1 of the private channel which is a counter 99 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 100 | 101 | // Check the status of the read operation to see if it was successful 102 | statusCode = ThingSpeak.getLastReadStatus(); 103 | if(statusCode == 200){ 104 | Serial.println("Counter: " + String(count)); 105 | } 106 | else{ 107 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 108 | } 109 | 110 | delay(15000); // No need to read the counter too often. 111 | 112 | } 113 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield/ReadField/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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 WiFi Shield 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires the WiFi library 12 | - Ensure the WiFi Shield has the latest firmware. Instruction to update can be found here: https://www.arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #include 27 | #include "secrets.h" 28 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 29 | 30 | char ssid[] = SECRET_SSID; // your network SSID (name) 31 | char pass[] = SECRET_PASS; // your network password 32 | int keyIndex = 0; // your network key Index number (needed only for WEP) 33 | WiFiClient client; 34 | 35 | unsigned long myChannelNumber = SECRET_CH_ID; 36 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 37 | 38 | // Initialize our values 39 | int number1 = 0; 40 | int number2 = random(0,100); 41 | int number3 = random(0,100); 42 | int number4 = random(0,100); 43 | String myStatus = ""; 44 | 45 | void setup() { 46 | //Initialize serial and wait for port to open: 47 | Serial.begin(115200); 48 | while (!Serial) { 49 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 50 | } 51 | 52 | // check for the presence of the shield: 53 | if (WiFi.status() == WL_NO_SHIELD) { 54 | Serial.println("WiFi shield not present"); 55 | // don't continue: 56 | while (true); 57 | } 58 | 59 | String fv = WiFi.firmwareVersion(); 60 | if (fv != "1.1.0") { 61 | Serial.println("Please upgrade the firmware"); 62 | } 63 | 64 | ThingSpeak.begin(client); // Initialize ThingSpeak 65 | } 66 | 67 | void loop() { 68 | 69 | // Connect or reconnect to WiFi 70 | if(WiFi.status() != WL_CONNECTED){ 71 | Serial.print("Attempting to connect to SSID: "); 72 | Serial.println(SECRET_SSID); 73 | while(WiFi.status() != WL_CONNECTED){ 74 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 75 | Serial.print("."); 76 | delay(5000); 77 | } 78 | Serial.println("\nConnected."); 79 | } 80 | 81 | // set the fields with the values 82 | ThingSpeak.setField(1, number1); 83 | ThingSpeak.setField(2, number2); 84 | ThingSpeak.setField(3, number3); 85 | ThingSpeak.setField(4, number4); 86 | 87 | // figure out the status message 88 | if(number1 > number2){ 89 | myStatus = String("field1 is greater than field2"); 90 | } 91 | else if(number1 < number2){ 92 | myStatus = String("field1 is less than field2"); 93 | } 94 | else{ 95 | myStatus = String("field1 equals field2"); 96 | } 97 | 98 | // set the status 99 | ThingSpeak.setStatus(myStatus); 100 | 101 | // write to the ThingSpeak channel 102 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 103 | if(x == 200){ 104 | Serial.println("Channel update successful."); 105 | } 106 | else{ 107 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 108 | } 109 | 110 | // change the values 111 | number1++; 112 | if(number1 > 99){ 113 | number1 = 0; 114 | } 115 | number2 = random(0,100); 116 | number3 = random(0,100); 117 | number4 = random(0,100); 118 | 119 | delay(20000); // Wait 20 seconds to update the channel again 120 | } 121 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: Arduino WiFi Shield 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires the WiFi library 12 | - Ensure the WiFi Shield has the latest firmware. Instruction to update can be found here: https://www.arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #include 27 | #include "secrets.h" 28 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 29 | 30 | char ssid[] = SECRET_SSID; // your network SSID (name) 31 | char pass[] = SECRET_PASS; // your network password 32 | int keyIndex = 0; // your network key Index number (needed only for WEP) 33 | WiFiClient client; 34 | 35 | unsigned long myChannelNumber = SECRET_CH_ID; 36 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 37 | 38 | int number = 0; 39 | 40 | void setup() { 41 | //Initialize serial and wait for port to open: 42 | Serial.begin(115200); 43 | while (!Serial) { 44 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 45 | } 46 | 47 | // check for the presence of the shield: 48 | if (WiFi.status() == WL_NO_SHIELD) { 49 | Serial.println("WiFi shield not present"); 50 | // don't continue: 51 | while (true); 52 | } 53 | 54 | String fv = WiFi.firmwareVersion(); 55 | if (fv != "1.1.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); 70 | Serial.print("."); 71 | delay(5000); 72 | } 73 | Serial.println("\nConnected."); 74 | } 75 | 76 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 77 | // pieces of information in a channel. Here, we write to field 1. 78 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 79 | if(x == 200){ 80 | Serial.println("Channel update successful."); 81 | } 82 | else{ 83 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 84 | } 85 | 86 | // change the value 87 | number++; 88 | if(number > 99){ 89 | number = 0; 90 | } 91 | 92 | delay(20000); // Wait 20 seconds to update the channel again 93 | } 94 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield101/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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 WiFi Shield 101 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | 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. 15 | - Make sure the WiFi 101 Shield has updated firmware. Find instructions here: https://www.arduino.cc/en/Tutorial/FirmwareUpdater 16 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 17 | 18 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 19 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 20 | 21 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 22 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 23 | 24 | For licensing information, see the accompanying license file. 25 | 26 | Copyright 2020, The MathWorks, Inc. 27 | */ 28 | 29 | #include 30 | #include "secrets.h" 31 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 32 | 33 | char ssid[] = SECRET_SSID; // your network SSID (name) 34 | char pass[] = SECRET_PASS; // your network password 35 | int keyIndex = 0; // your network key Index number (needed only for WEP) 36 | WiFiClient client; 37 | 38 | // Weather station channel details 39 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 40 | unsigned int temperatureFieldNumber = 4; 41 | 42 | // Counting channel details 43 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 44 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 45 | unsigned int counterFieldNumber = 1; 46 | 47 | void setup() { 48 | //Initialize serial and wait for port to open: 49 | Serial.begin(115200); 50 | while (!Serial) { 51 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 52 | } 53 | 54 | ThingSpeak.begin(client); // Initialize ThingSpeak 55 | } 56 | 57 | void loop() { 58 | 59 | int statusCode = 0; 60 | 61 | // Connect or reconnect to WiFi 62 | if(WiFi.status() != WL_CONNECTED){ 63 | Serial.print("Attempting to connect to SSID: "); 64 | Serial.println(SECRET_SSID); 65 | while(WiFi.status() != WL_CONNECTED){ 66 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 67 | Serial.print("."); 68 | delay(5000); 69 | } 70 | Serial.println("\nConnected"); 71 | } 72 | 73 | // Read in field 4 of the public channel recording the temperature 74 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 75 | 76 | // Check the status of the read operation to see if it was successful 77 | statusCode = ThingSpeak.getLastReadStatus(); 78 | if(statusCode == 200){ 79 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 80 | } 81 | else{ 82 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 83 | } 84 | 85 | delay(15000); // No need to read the temperature too often. 86 | 87 | // Read in field 1 of the private channel which is a counter 88 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 89 | 90 | // Check the status of the read operation to see if it was successful 91 | statusCode = ThingSpeak.getLastReadStatus(); 92 | if(statusCode == 200){ 93 | Serial.println("Counter: " + String(count)); 94 | } 95 | else{ 96 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 97 | } 98 | 99 | delay(15000); // No need to read the counter too often. 100 | 101 | } 102 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield101/ReadField/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield101/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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 WiFi Shield 101 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | 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. 13 | - Make sure the WiFi 101 Shield has updated firmware. Find instructions here: https://www.arduino.cc/en/Tutorial/FirmwareUpdater 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 2020, The MathWorks, Inc. 25 | */ 26 | 27 | #include 28 | #include "secrets.h" 29 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | unsigned long myChannelNumber = SECRET_CH_ID; 37 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 38 | 39 | // Initialize our values 40 | int number1 = 0; 41 | int number2 = random(0,100); 42 | int number3 = random(0,100); 43 | int number4 = random(0,100); 44 | String myStatus = ""; 45 | 46 | void setup() { 47 | //Initialize serial and wait for port to open: 48 | Serial.begin(115200); 49 | while (!Serial) { 50 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 51 | } 52 | 53 | ThingSpeak.begin(client); // Initialize ThingSpeak 54 | } 55 | 56 | void loop() { 57 | 58 | // Connect or reconnect to WiFi 59 | if(WiFi.status() != WL_CONNECTED){ 60 | Serial.print("Attempting to connect to SSID: "); 61 | Serial.println(SECRET_SSID); 62 | while(WiFi.status() != WL_CONNECTED){ 63 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 64 | Serial.print("."); 65 | delay(5000); 66 | } 67 | Serial.println("\nConnected."); 68 | } 69 | 70 | // set the fields with the values 71 | ThingSpeak.setField(1, number1); 72 | ThingSpeak.setField(2, number2); 73 | ThingSpeak.setField(3, number3); 74 | ThingSpeak.setField(4, number4); 75 | 76 | // figure out the status message 77 | if(number1 > number2){ 78 | myStatus = String("field1 is greater than field2"); 79 | } 80 | else if(number1 < number2){ 81 | myStatus = String("field1 is less than field2"); 82 | } 83 | else{ 84 | myStatus = String("field1 equals field2"); 85 | } 86 | 87 | // set the status 88 | ThingSpeak.setStatus(myStatus); 89 | 90 | // write to the ThingSpeak channel 91 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 92 | if(x == 200){ 93 | Serial.println("Channel update successful."); 94 | } 95 | else{ 96 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 97 | } 98 | 99 | // change the values 100 | number1++; 101 | if(number1 > 99){ 102 | number1 = 0; 103 | } 104 | number2 = random(0,100); 105 | number3 = random(0,100); 106 | number4 = random(0,100); 107 | 108 | delay(20000); // Wait 20 seconds to update the channel again 109 | } 110 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield101/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield101/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: Arduino WiFi Shield 101 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | 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. 13 | - Make sure the WiFi 101 Shield has updated firmware. Find instructions here: https://www.arduino.cc/en/Tutorial/FirmwareUpdater 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 2020, The MathWorks, Inc. 25 | */ 26 | 27 | #include 28 | #include "secrets.h" 29 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 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 | unsigned long myChannelNumber = SECRET_CH_ID; 37 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 38 | 39 | int number = 0; 40 | 41 | void setup() { 42 | //Initialize serial and wait for port to open: 43 | Serial.begin(115200); 44 | while (!Serial) { 45 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 46 | } 47 | 48 | ThingSpeak.begin(client); // Initialize ThingSpeak 49 | } 50 | 51 | void loop() { 52 | 53 | // Connect or reconnect to WiFi 54 | if(WiFi.status() != WL_CONNECTED){ 55 | Serial.print("Attempting to connect to SSID: "); 56 | Serial.println(SECRET_SSID); 57 | while(WiFi.status() != WL_CONNECTED){ 58 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 59 | Serial.print("."); 60 | delay(5000); 61 | } 62 | Serial.println("\nConnected."); 63 | } 64 | 65 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 66 | // pieces of information in a channel. Here, we write to field 1. 67 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 68 | if(x == 200){ 69 | Serial.println("Channel update successful."); 70 | } 71 | else{ 72 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 73 | } 74 | 75 | // change the value 76 | number++; 77 | if(number > 99){ 78 | number = 0; 79 | } 80 | 81 | delay(20000); // Wait 20 seconds to update the channel again 82 | } 83 | -------------------------------------------------------------------------------- /examples/ArduinoWiFiShield101/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /examples/ArduinoYun/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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 Yún, Yún Rev.2 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Notes: 13 | - This example works with both Ethernet and WiFi 14 | - For WiFi with the Yún Rev.2, configure the SSID and password through the Access Point portal. 15 | See https://www.arduino.cc/en/Guide/ArduinoYunRev2 for details. 16 | 17 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 18 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 19 | 20 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 21 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 22 | 23 | For licensing information, see the accompanying license file. 24 | 25 | Copyright 2020, The MathWorks, Inc. 26 | */ 27 | 28 | #include 29 | #include "secrets.h" 30 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 31 | 32 | BridgeClient client; 33 | 34 | // Weather station channel details 35 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 36 | unsigned int temperatureFieldNumber = 4; 37 | 38 | // Counting channel details 39 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 40 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 41 | unsigned int counterFieldNumber = 1; 42 | 43 | void setup() { 44 | Serial.begin(115200); //Initialize serial 45 | while (!Serial) { 46 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 47 | } 48 | 49 | Bridge.begin(); 50 | ThingSpeak.begin(client); // Initialize ThingSpeak 51 | } 52 | 53 | void loop() { 54 | 55 | int statusCode = 0; 56 | 57 | // Read in field 4 of the public channel recording the temperature 58 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 59 | 60 | // Check the status of the read operation to see if it was successful 61 | statusCode = ThingSpeak.getLastReadStatus(); 62 | if(statusCode == 200){ 63 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 64 | } 65 | else{ 66 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 67 | } 68 | 69 | delay(15000); // No need to read the temperature too often. 70 | 71 | // Read in field 1 of the private channel which is a counter 72 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 73 | 74 | // Check the status of the read operation to see if it was successful 75 | statusCode = ThingSpeak.getLastReadStatus(); 76 | if(statusCode == 200){ 77 | Serial.println("Counter: " + String(count)); 78 | } 79 | else{ 80 | Serial.print("Problem reading channel. HTTP error code "); 81 | Serial.println(statusCode); 82 | } 83 | 84 | delay(15000); // No need to read the counter too often. 85 | 86 | } 87 | -------------------------------------------------------------------------------- /examples/ArduinoYun/ReadField/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | #define SECRET_CH_ID_WEATHER_STATION 12397 //MathWorks weather station 5 | 6 | #define SECRET_CH_ID_COUNTER 298725 //Test channel for counting 7 | #define SECRET_READ_APIKEY_COUNTER "SODG0O2UZVGKWAWG" //API Key for Test channel 8 | -------------------------------------------------------------------------------- /examples/ArduinoYun/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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 Yún, Yún Rev.2 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - This example works with both Ethernet and WiFi 12 | - For WiFi with the Yún Rev.2, configure the SSID and password through the Access Point portal. 13 | See https://www.arduino.cc/en/Guide/ArduinoYunRev2 for details. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | #include 26 | #include "secrets.h" 27 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 28 | 29 | BridgeClient client; 30 | unsigned long myChannelNumber = SECRET_CH_ID; 31 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 32 | 33 | // Initialize our values 34 | int number1 = 0; 35 | int number2 = random(0,100); 36 | int number3 = random(0,100); 37 | int number4 = random(0,100); 38 | String myStatus = ""; 39 | 40 | void setup() { 41 | Serial.begin(115200); //Initialize serial 42 | while (!Serial) { 43 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 44 | } 45 | 46 | Bridge.begin(); 47 | ThingSpeak.begin(client); // Initialize ThingSpeak 48 | } 49 | 50 | void loop() { 51 | 52 | // set the fields with the values 53 | ThingSpeak.setField(1, number1); 54 | ThingSpeak.setField(2, number2); 55 | ThingSpeak.setField(3, number3); 56 | ThingSpeak.setField(4, number4); 57 | 58 | // figure out the status message 59 | if(number1 > number2){ 60 | myStatus = String("field1 is greater than field2"); 61 | } 62 | else if(number1 < number2){ 63 | myStatus = String("field1 is less than field2"); 64 | } 65 | else{ 66 | myStatus = String("field1 equals field2"); 67 | } 68 | 69 | // set the status 70 | ThingSpeak.setStatus(myStatus); 71 | 72 | // write to the ThingSpeak channel 73 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 74 | if(x == 200){ 75 | Serial.println("Channel update successful."); 76 | } 77 | else{ 78 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 79 | } 80 | 81 | // change the values 82 | number1++; 83 | if(number1 > 99){ 84 | number1 = 0; 85 | } 86 | number2 = random(0,100); 87 | number3 = random(0,100); 88 | number4 = random(0,100); 89 | 90 | delay(20000); // Wait 20 seconds to update the channel again 91 | } 92 | -------------------------------------------------------------------------------- /examples/ArduinoYun/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 5 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 6 | -------------------------------------------------------------------------------- /examples/ArduinoYun/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: Arduino Yún, Yún Rev.2 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Notes: 11 | - This example works with both Ethernet and WiFi 12 | - For WiFi with the Yún Rev.2, configure the SSID and password through the Access Point portal. 13 | See https://www.arduino.cc/en/Guide/ArduinoYunRev2 for details. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #include 27 | #include "secrets.h" 28 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 29 | 30 | BridgeClient client; 31 | unsigned long myChannelNumber = SECRET_CH_ID; 32 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 33 | 34 | int number = 0; 35 | 36 | void setup() { 37 | Serial.begin(115200); //Initialize serial 38 | while (!Serial) { 39 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 40 | } 41 | 42 | Bridge.begin(); 43 | ThingSpeak.begin(client); // Initialize ThingSpeak 44 | } 45 | 46 | void loop() { 47 | 48 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 49 | // pieces of information in a channel. Here, we write to field 1. 50 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 51 | if(x == 200){ 52 | Serial.println("Channel update successful."); 53 | } 54 | else{ 55 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 56 | } 57 | 58 | // change the value 59 | number++; 60 | if(number > 99){ 61 | number = 0; 62 | } 63 | 64 | delay(20000); // Wait 20 seconds to update the channel again 65 | } 66 | -------------------------------------------------------------------------------- /examples/ArduinoYun/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 1 | // Use this file to store all of the private credentials 2 | // and connection details 3 | 4 | #define SECRET_CH_ID 000000 // replace 0000000 with your channel number 5 | #define SECRET_WRITE_APIKEY "XYZ" // replace XYZ with your channel write API Key 6 | -------------------------------------------------------------------------------- /examples/ESP32/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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: ESP32 based boards 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires installation of EPS32 core. See https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md for details. 14 | - Select the target hardware from the Tools->Board menu 15 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 16 | 17 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 18 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 19 | 20 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 21 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 22 | 23 | For licensing information, see the accompanying license file. 24 | 25 | Copyright 2020, The MathWorks, Inc. 26 | */ 27 | 28 | #include 29 | #include "secrets.h" 30 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 31 | 32 | char ssid[] = SECRET_SSID; // your network SSID (name) 33 | char pass[] = SECRET_PASS; // your network password 34 | int keyIndex = 0; // your network key Index number (needed only for WEP) 35 | WiFiClient client; 36 | 37 | // Weather station channel details 38 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 39 | unsigned int temperatureFieldNumber = 4; 40 | 41 | // Counting channel details 42 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 43 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 44 | unsigned int counterFieldNumber = 1; 45 | 46 | void setup() { 47 | Serial.begin(115200); //Initialize serial 48 | while (!Serial) { 49 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 50 | } 51 | 52 | WiFi.mode(WIFI_STA); 53 | ThingSpeak.begin(client); // Initialize ThingSpeak 54 | } 55 | 56 | void loop() { 57 | 58 | int statusCode = 0; 59 | 60 | // Connect or reconnect to WiFi 61 | if(WiFi.status() != WL_CONNECTED){ 62 | Serial.print("Attempting to connect to SSID: "); 63 | Serial.println(SECRET_SSID); 64 | while(WiFi.status() != WL_CONNECTED){ 65 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 66 | Serial.print("."); 67 | delay(5000); 68 | } 69 | Serial.println("\nConnected"); 70 | } 71 | 72 | // Read in field 4 of the public channel recording the temperature 73 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 74 | 75 | // Check the status of the read operation to see if it was successful 76 | statusCode = ThingSpeak.getLastReadStatus(); 77 | if(statusCode == 200){ 78 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 79 | } 80 | else{ 81 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 82 | } 83 | 84 | delay(15000); // No need to read the temperature too often. 85 | 86 | // Read in field 1 of the private channel which is a counter 87 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 88 | 89 | // Check the status of the read operation to see if it was successful 90 | statusCode = ThingSpeak.getLastReadStatus(); 91 | if(statusCode == 200){ 92 | Serial.println("Counter: " + String(count)); 93 | } 94 | else{ 95 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 96 | } 97 | 98 | delay(15000); // No need to read the counter too often. 99 | 100 | } 101 | -------------------------------------------------------------------------------- /examples/ESP32/ReadField/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ESP32/ReadFieldSecure/ReadFieldSecure.ino: -------------------------------------------------------------------------------- 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 over secured HTTPS connection. 7 | 8 | Hardware: ESP32 based boards 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires installation of EPS32 core and WiFiClientSecure library. See https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md for details. 14 | - Select the target hardware from the Tools->Board menu 15 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 16 | 17 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 18 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 19 | 20 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 21 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 22 | 23 | For licensing information, see the accompanying license file. 24 | 25 | Copyright 2020, The MathWorks, Inc. 26 | */ 27 | 28 | #define TS_ENABLE_SSL // For HTTPS SSL connection 29 | 30 | #include 31 | #include "secrets.h" 32 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 33 | 34 | char ssid[] = SECRET_SSID; // your network SSID (name) 35 | char pass[] = SECRET_PASS; // your network password 36 | int keyIndex = 0; // your network key Index number (needed only for WEP) 37 | WiFiClientSecure client; 38 | 39 | // Weather station channel details 40 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 41 | unsigned int temperatureFieldNumber = 4; 42 | 43 | // Counting channel details 44 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 45 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 46 | unsigned int counterFieldNumber = 1; 47 | 48 | void setup() { 49 | Serial.begin(115200); //Initialize serial 50 | while (!Serial) { 51 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 52 | } 53 | 54 | WiFi.mode(WIFI_STA); 55 | ThingSpeak.begin(client); // Initialize ThingSpeak 56 | } 57 | 58 | void loop() { 59 | 60 | int statusCode = 0; 61 | 62 | // Connect or reconnect to WiFi 63 | if(WiFi.status() != WL_CONNECTED){ 64 | Serial.print("Attempting to connect to SSID: "); 65 | Serial.println(SECRET_SSID); 66 | while(WiFi.status() != WL_CONNECTED){ 67 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 68 | Serial.print("."); 69 | delay(5000); 70 | } 71 | Serial.println("\nConnected"); 72 | } 73 | 74 | // Read in field 4 of the public channel recording the temperature 75 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 76 | 77 | // Check the status of the read operation to see if it was successful 78 | statusCode = ThingSpeak.getLastReadStatus(); 79 | if(statusCode == 200){ 80 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 81 | } 82 | else{ 83 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 84 | } 85 | 86 | delay(15000); // No need to read the temperature too often. 87 | 88 | // Read in field 1 of the private channel which is a counter 89 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 90 | 91 | // Check the status of the read operation to see if it was successful 92 | statusCode = ThingSpeak.getLastReadStatus(); 93 | if(statusCode == 200){ 94 | Serial.println("Counter: " + String(count)); 95 | } 96 | else{ 97 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 98 | } 99 | 100 | delay(15000); // No need to read the counter too often. 101 | 102 | } 103 | -------------------------------------------------------------------------------- /examples/ESP32/ReadFieldSecure/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ESP32/ReadMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /examples/ESP32/ReadMultipleFieldsSecure/secrets.h: -------------------------------------------------------------------------------- 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 | // ThingSpeak Root Certificate, Expiration Date: November 9, 2031 at 7:00:00 PM EST 10 | #define SECRET_TS_ROOT_CA "-----BEGIN CERTIFICATE-----\n" \ 11 | "MIIDxTCCAq2gAwIBAgIQAqxcJmoLQJuPC3nyrkYldzANBgkqhkiG9w0BAQUFADBs\n" \ 12 | "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \ 13 | "d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j\n" \ 14 | "ZSBFViBSb290IENBMB4XDTA2MTExMDAwMDAwMFoXDTMxMTExMDAwMDAwMFowbDEL\n" \ 15 | "MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3\n" \ 16 | "LmRpZ2ljZXJ0LmNvbTErMCkGA1UEAxMiRGlnaUNlcnQgSGlnaCBBc3N1cmFuY2Ug\n" \ 17 | "RVYgUm9vdCBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbM5XPm\n" \ 18 | "+9S75S0tMqbf5YE/yc0lSbZxKsPVlDRnogocsF9ppkCxxLeyj9CYpKlBWTrT3JTW\n" \ 19 | "PNt0OKRKzE0lgvdKpVMSOO7zSW1xkX5jtqumX8OkhPhPYlG++MXs2ziS4wblCJEM\n" \ 20 | "xChBVfvLWokVfnHoNb9Ncgk9vjo4UFt3MRuNs8ckRZqnrG0AFFoEt7oT61EKmEFB\n" \ 21 | "Ik5lYYeBQVCmeVyJ3hlKV9Uu5l0cUyx+mM0aBhakaHPQNAQTXKFx01p8VdteZOE3\n" \ 22 | "hzBWBOURtCmAEvF5OYiiAhF8J2a3iLd48soKqDirCmTCv2ZdlYTBoSUeh10aUAsg\n" \ 23 | "EsxBu24LUTi4S8sCAwEAAaNjMGEwDgYDVR0PAQH/BAQDAgGGMA8GA1UdEwEB/wQF\n" \ 24 | "MAMBAf8wHQYDVR0OBBYEFLE+w2kD+L9HAdSYJhoIAu9jZCvDMB8GA1UdIwQYMBaA\n" \ 25 | "FLE+w2kD+L9HAdSYJhoIAu9jZCvDMA0GCSqGSIb3DQEBBQUAA4IBAQAcGgaX3Nec\n" \ 26 | "nzyIZgYIVyHbIUf4KmeqvxgydkAQV8GK83rZEWWONfqe/EW1ntlMMUu4kehDLI6z\n" \ 27 | "eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF\n" \ 28 | "hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2\n" \ 29 | "Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe\n" \ 30 | "vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep\n" \ 31 | "+OkuE6N36B9K\n" \ 32 | "-----END CERTIFICATE-----\n" 33 | -------------------------------------------------------------------------------- /examples/ESP32/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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: ESP32 based boards 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires installation of EPS32 core. See https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md for details. 12 | - Select the target hardware from the Tools->Board menu 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #include 27 | #include "secrets.h" 28 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 29 | 30 | char ssid[] = SECRET_SSID; // your network SSID (name) 31 | char pass[] = SECRET_PASS; // your network password 32 | int keyIndex = 0; // your network key Index number (needed only for WEP) 33 | WiFiClient client; 34 | 35 | unsigned long myChannelNumber = SECRET_CH_ID; 36 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 37 | 38 | // Initialize our values 39 | int number1 = 0; 40 | int number2 = random(0,100); 41 | int number3 = random(0,100); 42 | int number4 = random(0,100); 43 | String myStatus = ""; 44 | 45 | void setup() { 46 | Serial.begin(115200); //Initialize serial 47 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 49 | } 50 | 51 | WiFi.mode(WIFI_STA); 52 | ThingSpeak.begin(client); // Initialize ThingSpeak 53 | } 54 | 55 | void loop() { 56 | 57 | // Connect or reconnect to WiFi 58 | if(WiFi.status() != WL_CONNECTED){ 59 | Serial.print("Attempting to connect to SSID: "); 60 | Serial.println(SECRET_SSID); 61 | while(WiFi.status() != WL_CONNECTED){ 62 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 63 | Serial.print("."); 64 | delay(5000); 65 | } 66 | Serial.println("\nConnected."); 67 | } 68 | 69 | // set the fields with the values 70 | ThingSpeak.setField(1, number1); 71 | ThingSpeak.setField(2, number2); 72 | ThingSpeak.setField(3, number3); 73 | ThingSpeak.setField(4, number4); 74 | 75 | // figure out the status message 76 | if(number1 > number2){ 77 | myStatus = String("field1 is greater than field2"); 78 | } 79 | else if(number1 < number2){ 80 | myStatus = String("field1 is less than field2"); 81 | } 82 | else{ 83 | myStatus = String("field1 equals field2"); 84 | } 85 | 86 | // set the status 87 | ThingSpeak.setStatus(myStatus); 88 | 89 | // write to the ThingSpeak channel 90 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 91 | if(x == 200){ 92 | Serial.println("Channel update successful."); 93 | } 94 | else{ 95 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 96 | } 97 | 98 | // change the values 99 | number1++; 100 | if(number1 > 99){ 101 | number1 = 0; 102 | } 103 | number2 = random(0,100); 104 | number3 = random(0,100); 105 | number4 = random(0,100); 106 | 107 | delay(20000); // Wait 20 seconds to update the channel again 108 | } 109 | -------------------------------------------------------------------------------- /examples/ESP32/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ESP32/WriteMultipleFieldsSecure/WriteMultipleFieldsSecure.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteMultipleFields 3 | 4 | Description: Writes values to fields 1,2,3,4 and status in a single ThingSpeak update every 20 seconds over secured HTTPS connection. 5 | 6 | Hardware: ESP32 based boards 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires installation of EPS32 core and WiFiClientSecure library. See https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md for details. 12 | - Select the target hardware from the Tools->Board menu 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #define TS_ENABLE_SSL // For HTTPS SSL connection 27 | 28 | #include 29 | #include "secrets.h" 30 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 31 | 32 | char ssid[] = SECRET_SSID; // your network SSID (name) 33 | char pass[] = SECRET_PASS; // your network password 34 | int keyIndex = 0; // your network key Index number (needed only for WEP) 35 | WiFiClientSecure client; 36 | 37 | unsigned long myChannelNumber = SECRET_CH_ID; 38 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 39 | 40 | // Initialize our values 41 | int number1 = 0; 42 | int number2 = random(0,100); 43 | int number3 = random(0,100); 44 | int number4 = random(0,100); 45 | String myStatus = ""; 46 | 47 | const char * fingerprint = SECRET_SHA1_FINGERPRINT; 48 | 49 | void setup() { 50 | Serial.begin(115200); //Initialize serial 51 | while (!Serial) { 52 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 53 | } 54 | 55 | WiFi.mode(WIFI_STA); 56 | ThingSpeak.begin(client); // Initialize ThingSpeak 57 | } 58 | 59 | void loop() { 60 | 61 | // Connect or reconnect to WiFi 62 | if(WiFi.status() != WL_CONNECTED){ 63 | Serial.print("Attempting to connect to SSID: "); 64 | Serial.println(SECRET_SSID); 65 | while(WiFi.status() != WL_CONNECTED){ 66 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 67 | Serial.print("."); 68 | delay(5000); 69 | } 70 | Serial.println("\nConnected."); 71 | } 72 | 73 | // set the fields with the values 74 | ThingSpeak.setField(1, number1); 75 | ThingSpeak.setField(2, number2); 76 | ThingSpeak.setField(3, number3); 77 | ThingSpeak.setField(4, number4); 78 | 79 | // figure out the status message 80 | if(number1 > number2){ 81 | myStatus = String("field1 is greater than field2"); 82 | } 83 | else if(number1 < number2){ 84 | myStatus = String("field1 is less than field2"); 85 | } 86 | else{ 87 | myStatus = String("field1 equals field2"); 88 | } 89 | 90 | // set the status 91 | ThingSpeak.setStatus(myStatus); 92 | 93 | // write to the ThingSpeak channel 94 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 95 | if(x == 200){ 96 | Serial.println("Channel update successful."); 97 | } 98 | else{ 99 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 100 | } 101 | 102 | // change the values 103 | number1++; 104 | if(number1 > 99){ 105 | number1 = 0; 106 | } 107 | number2 = random(0,100); 108 | number3 = random(0,100); 109 | number4 = random(0,100); 110 | 111 | delay(5000); // Wait 20 seconds to update the channel again 112 | } 113 | -------------------------------------------------------------------------------- /examples/ESP32/WriteMultipleFieldsSecure/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ESP32/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: ESP32 based boards 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires installation of EPS32 core. See https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md for details. 12 | - Select the target hardware from the Tools->Board menu 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #include 27 | #include "secrets.h" 28 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 29 | 30 | char ssid[] = SECRET_SSID; // your network SSID (name) 31 | char pass[] = SECRET_PASS; // your network password 32 | int keyIndex = 0; // your network key Index number (needed only for WEP) 33 | WiFiClient client; 34 | 35 | unsigned long myChannelNumber = SECRET_CH_ID; 36 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 37 | 38 | int number = 0; 39 | 40 | void setup() { 41 | Serial.begin(115200); //Initialize serial 42 | while (!Serial) { 43 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 44 | } 45 | 46 | WiFi.mode(WIFI_STA); 47 | ThingSpeak.begin(client); // Initialize ThingSpeak 48 | } 49 | 50 | void loop() { 51 | 52 | // Connect or reconnect to WiFi 53 | if(WiFi.status() != WL_CONNECTED){ 54 | Serial.print("Attempting to connect to SSID: "); 55 | Serial.println(SECRET_SSID); 56 | while(WiFi.status() != WL_CONNECTED){ 57 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 58 | Serial.print("."); 59 | delay(5000); 60 | } 61 | Serial.println("\nConnected."); 62 | } 63 | 64 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 65 | // pieces of information in a channel. Here, we write to field 1. 66 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 67 | if(x == 200){ 68 | Serial.println("Channel update successful."); 69 | } 70 | else{ 71 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 72 | } 73 | 74 | // change the value 75 | number++; 76 | if(number > 99){ 77 | number = 0; 78 | } 79 | 80 | delay(20000); // Wait 20 seconds to update the channel again 81 | } 82 | -------------------------------------------------------------------------------- /examples/ESP32/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ESP32/WriteSingleFieldSecure/WriteSingleFieldSecure.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds over secured HTTPS connection. 5 | 6 | Hardware: ESP32 based boards 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires installation of EPS32 core and WiFiClientSecure library. See https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/boards_manager.md for details. 12 | - Select the target hardware from the Tools->Board menu 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #define TS_ENABLE_SSL // For HTTPS SSL connection 27 | 28 | #include 29 | #include "secrets.h" 30 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 31 | 32 | char ssid[] = SECRET_SSID; // your network SSID (name) 33 | char pass[] = SECRET_PASS; // your network password 34 | int keyIndex = 0; // your network key Index number (needed only for WEP) 35 | WiFiClientSecure client; 36 | 37 | unsigned long myChannelNumber = SECRET_CH_ID; 38 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 39 | 40 | int number = 0; 41 | 42 | void setup() { 43 | Serial.begin(115200); //Initialize serial 44 | while (!Serial) { 45 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 46 | } 47 | 48 | WiFi.mode(WIFI_STA); 49 | ThingSpeak.begin(client); // Initialize ThingSpeak 50 | } 51 | 52 | void loop() { 53 | 54 | // Connect or reconnect to WiFi 55 | if(WiFi.status() != WL_CONNECTED){ 56 | Serial.print("Attempting to connect to SSID: "); 57 | Serial.println(SECRET_SSID); 58 | while(WiFi.status() != WL_CONNECTED){ 59 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 60 | Serial.print("."); 61 | delay(5000); 62 | } 63 | Serial.println("\nConnected."); 64 | } 65 | 66 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 67 | // pieces of information in a channel. Here, we write to field 1. 68 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 69 | if(x == 200){ 70 | Serial.println("Channel update successful."); 71 | } 72 | else{ 73 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 74 | } 75 | 76 | // change the value 77 | number++; 78 | if(number > 99){ 79 | number = 0; 80 | } 81 | 82 | delay(20000); // Wait 20 seconds to update the channel again 83 | } 84 | -------------------------------------------------------------------------------- /examples/ESP32/WriteSingleFieldSecure/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/ReadField/ReadField.ino: -------------------------------------------------------------------------------- 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: ESP8266 based boards 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires ESP8266WiFi library and ESP8622 board add-on. See https://github.com/esp8266/Arduino for details. 14 | - Select the target hardware from the Tools->Board menu 15 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 16 | 17 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 18 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 19 | 20 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 21 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 22 | 23 | For licensing information, see the accompanying license file. 24 | 25 | Copyright 2020, The MathWorks, Inc. 26 | */ 27 | 28 | #include 29 | #include "secrets.h" 30 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 31 | 32 | char ssid[] = SECRET_SSID; // your network SSID (name) 33 | char pass[] = SECRET_PASS; // your network password 34 | int keyIndex = 0; // your network key Index number (needed only for WEP) 35 | WiFiClient client; 36 | 37 | // Weather station channel details 38 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 39 | unsigned int temperatureFieldNumber = 4; 40 | 41 | // Counting channel details 42 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 43 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 44 | unsigned int counterFieldNumber = 1; 45 | 46 | void setup() { 47 | Serial.begin(115200); // Initialize serial 48 | while (!Serial) { 49 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 50 | } 51 | 52 | WiFi.mode(WIFI_STA); 53 | ThingSpeak.begin(client); // Initialize ThingSpeak 54 | } 55 | 56 | void loop() { 57 | 58 | int statusCode = 0; 59 | 60 | // Connect or reconnect to WiFi 61 | if(WiFi.status() != WL_CONNECTED){ 62 | Serial.print("Attempting to connect to SSID: "); 63 | Serial.println(SECRET_SSID); 64 | while(WiFi.status() != WL_CONNECTED){ 65 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 66 | Serial.print("."); 67 | delay(5000); 68 | } 69 | Serial.println("\nConnected"); 70 | } 71 | 72 | // Read in field 4 of the public channel recording the temperature 73 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 74 | 75 | // Check the status of the read operation to see if it was successful 76 | statusCode = ThingSpeak.getLastReadStatus(); 77 | if(statusCode == 200){ 78 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 79 | } 80 | else{ 81 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 82 | } 83 | 84 | delay(15000); // No need to read the temperature too often. 85 | 86 | // Read in field 1 of the private channel which is a counter 87 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 88 | 89 | // Check the status of the read operation to see if it was successful 90 | statusCode = ThingSpeak.getLastReadStatus(); 91 | if(statusCode == 200){ 92 | Serial.println("Counter: " + String(count)); 93 | } 94 | else{ 95 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 96 | } 97 | 98 | delay(15000); // No need to read the counter too often. 99 | 100 | } 101 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/ReadField/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/ReadFieldSecure/ReadFieldSecure.ino: -------------------------------------------------------------------------------- 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 over secured HTTPS connection. 7 | 8 | Hardware: ESP8266 based boards 9 | 10 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 11 | 12 | Note: 13 | - Requires ESP8266WiFi library, WiFiClientSecure library and ESP8622 board add-on. See https://github.com/esp8266/Arduino for details. 14 | - Select the target hardware from the Tools->Board menu 15 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 16 | 17 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 18 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 19 | 20 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 21 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 22 | 23 | For licensing information, see the accompanying license file. 24 | 25 | Copyright 2020, The MathWorks, Inc. 26 | */ 27 | 28 | #define TS_ENABLE_SSL // For HTTPS SSL connection 29 | 30 | #include 31 | #include 32 | #include "secrets.h" 33 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 34 | 35 | char ssid[] = SECRET_SSID; // your network SSID (name) 36 | char pass[] = SECRET_PASS; // your network password 37 | int keyIndex = 0; // your network key Index number (needed only for WEP) 38 | WiFiClientSecure client; 39 | 40 | // Weather station channel details 41 | unsigned long weatherStationChannelNumber = SECRET_CH_ID_WEATHER_STATION; 42 | unsigned int temperatureFieldNumber = 4; 43 | 44 | // Counting channel details 45 | unsigned long counterChannelNumber = SECRET_CH_ID_COUNTER; 46 | const char * myCounterReadAPIKey = SECRET_READ_APIKEY_COUNTER; 47 | unsigned int counterFieldNumber = 1; 48 | 49 | // Fingerprint check, make sure that the certificate has not expired. 50 | const char * fingerprint = NULL; // use SECRET_SHA1_FINGERPRINT for fingerprint check 51 | 52 | void setup() { 53 | Serial.begin(115200); // Initialize serial 54 | while (!Serial) { 55 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 56 | } 57 | 58 | WiFi.mode(WIFI_STA); 59 | 60 | if(fingerprint!=NULL){ 61 | client.setFingerprint(fingerprint); 62 | } 63 | else{ 64 | client.setInsecure(); // To perform a simple SSL Encryption 65 | } 66 | 67 | ThingSpeak.begin(client); // Initialize ThingSpeak 68 | } 69 | 70 | void loop() { 71 | 72 | int statusCode = 0; 73 | 74 | // Connect or reconnect to WiFi 75 | if(WiFi.status() != WL_CONNECTED){ 76 | Serial.print("Attempting to connect to SSID: "); 77 | Serial.println(SECRET_SSID); 78 | while(WiFi.status() != WL_CONNECTED){ 79 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 80 | Serial.print("."); 81 | delay(5000); 82 | } 83 | Serial.println("\nConnected"); 84 | } 85 | 86 | // Read in field 4 of the public channel recording the temperature 87 | float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber); 88 | 89 | // Check the status of the read operation to see if it was successful 90 | statusCode = ThingSpeak.getLastReadStatus(); 91 | if(statusCode == 200){ 92 | Serial.println("Temperature at MathWorks HQ: " + String(temperatureInF) + " deg F"); 93 | } 94 | else{ 95 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 96 | } 97 | 98 | delay(15000); // No need to read the temperature too often. 99 | 100 | // Read in field 1 of the private channel which is a counter 101 | long count = ThingSpeak.readLongField(counterChannelNumber, counterFieldNumber, myCounterReadAPIKey); 102 | 103 | // Check the status of the read operation to see if it was successful 104 | statusCode = ThingSpeak.getLastReadStatus(); 105 | if(statusCode == 200){ 106 | Serial.println("Counter: " + String(count)); 107 | } 108 | else{ 109 | Serial.println("Problem reading channel. HTTP error code " + String(statusCode)); 110 | } 111 | 112 | delay(15000); // No need to read the counter too often. 113 | 114 | } 115 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/ReadFieldSecure/secrets.h: -------------------------------------------------------------------------------- 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 11 | 12 | // ThingSpeak Certificate Fingerprint, Expiration Date: August 3, 2022 at 8:00:00 AM EST 13 | #define SECRET_SHA1_FINGERPRINT "27 18 92 DD A4 26 C3 07 09 B9 7A E6 C5 21 B9 5B 48 F7 16 E1" 14 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/ReadMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/ReadMultipleFieldsSecure/secrets.h: -------------------------------------------------------------------------------- 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 | // ThingSpeak Certificate Fingerprint, Expiration Date: August 3, 2022 at 8:00:00 AM EST 10 | #define SECRET_SHA1_FINGERPRINT "27 18 92 DD A4 26 C3 07 09 B9 7A E6 C5 21 B9 5B 48 F7 16 E1" 11 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/WriteMultipleFields/WriteMultipleFields.ino: -------------------------------------------------------------------------------- 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: ESP8266 based boards 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires ESP8266WiFi library and ESP8622 board add-on. See https://github.com/esp8266/Arduino for details. 12 | - Select the target hardware from the Tools->Board menu 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #include 27 | #include "secrets.h" 28 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 29 | 30 | char ssid[] = SECRET_SSID; // your network SSID (name) 31 | char pass[] = SECRET_PASS; // your network password 32 | int keyIndex = 0; // your network key Index number (needed only for WEP) 33 | WiFiClient client; 34 | 35 | unsigned long myChannelNumber = SECRET_CH_ID; 36 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 37 | 38 | // Initialize our values 39 | int number1 = 0; 40 | int number2 = random(0,100); 41 | int number3 = random(0,100); 42 | int number4 = random(0,100); 43 | String myStatus = ""; 44 | 45 | void setup() { 46 | Serial.begin(115200); // Initialize serial 47 | while (!Serial) { 48 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 49 | } 50 | 51 | WiFi.mode(WIFI_STA); 52 | ThingSpeak.begin(client); // Initialize ThingSpeak 53 | } 54 | 55 | void loop() { 56 | 57 | // Connect or reconnect to WiFi 58 | if(WiFi.status() != WL_CONNECTED){ 59 | Serial.print("Attempting to connect to SSID: "); 60 | Serial.println(SECRET_SSID); 61 | while(WiFi.status() != WL_CONNECTED){ 62 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 63 | Serial.print("."); 64 | delay(5000); 65 | } 66 | Serial.println("\nConnected."); 67 | } 68 | 69 | // set the fields with the values 70 | ThingSpeak.setField(1, number1); 71 | ThingSpeak.setField(2, number2); 72 | ThingSpeak.setField(3, number3); 73 | ThingSpeak.setField(4, number4); 74 | 75 | // figure out the status message 76 | if(number1 > number2){ 77 | myStatus = String("field1 is greater than field2"); 78 | } 79 | else if(number1 < number2){ 80 | myStatus = String("field1 is less than field2"); 81 | } 82 | else{ 83 | myStatus = String("field1 equals field2"); 84 | } 85 | 86 | // set the status 87 | ThingSpeak.setStatus(myStatus); 88 | 89 | // write to the ThingSpeak channel 90 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 91 | if(x == 200){ 92 | Serial.println("Channel update successful."); 93 | } 94 | else{ 95 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 96 | } 97 | 98 | // change the values 99 | number1++; 100 | if(number1 > 99){ 101 | number1 = 0; 102 | } 103 | number2 = random(0,100); 104 | number3 = random(0,100); 105 | number4 = random(0,100); 106 | 107 | delay(20000); // Wait 20 seconds to update the channel again 108 | } 109 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/WriteMultipleFieldsSecure/WriteMultipleFieldsSecure.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteMultipleFields 3 | 4 | Description: Writes values to fields 1,2,3,4 and status in a single ThingSpeak update every 20 seconds over secured HTTPS connection. 5 | 6 | Hardware: ESP8266 based boards 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires ESP8266WiFi library, WiFiClientSecure library and ESP8622 board add-on. See https://github.com/esp8266/Arduino for details. 12 | - Select the target hardware from the Tools->Board menu 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #define TS_ENABLE_SSL // For HTTPS SSL connection 27 | 28 | #include 29 | #include 30 | #include "secrets.h" 31 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 32 | 33 | char ssid[] = SECRET_SSID; // your network SSID (name) 34 | char pass[] = SECRET_PASS; // your network password 35 | int keyIndex = 0; // your network key Index number (needed only for WEP) 36 | WiFiClientSecure client; 37 | 38 | unsigned long myChannelNumber = SECRET_CH_ID; 39 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 40 | 41 | // Initialize our values 42 | int number1 = 0; 43 | int number2 = random(0,100); 44 | int number3 = random(0,100); 45 | int number4 = random(0,100); 46 | String myStatus = ""; 47 | 48 | // Fingerprint check, make sure that the certificate has not expired. 49 | const char * fingerprint = NULL; // use SECRET_SHA1_FINGERPRINT for fingerprint check 50 | 51 | void setup() { 52 | Serial.begin(115200); // Initialize serial 53 | while (!Serial) { 54 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 55 | } 56 | 57 | WiFi.mode(WIFI_STA); 58 | 59 | if(fingerprint!=NULL){ 60 | client.setFingerprint(fingerprint); 61 | } 62 | else{ 63 | client.setInsecure(); // To perform a simple SSL Encryption 64 | } 65 | 66 | ThingSpeak.begin(client); // Initialize ThingSpeak 67 | } 68 | 69 | void loop() { 70 | 71 | // Connect or reconnect to WiFi 72 | if(WiFi.status() != WL_CONNECTED){ 73 | Serial.print("Attempting to connect to SSID: "); 74 | Serial.println(SECRET_SSID); 75 | while(WiFi.status() != WL_CONNECTED){ 76 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 77 | Serial.print("."); 78 | delay(5000); 79 | } 80 | Serial.println("\nConnected."); 81 | } 82 | 83 | // set the fields with the values 84 | ThingSpeak.setField(1, number1); 85 | ThingSpeak.setField(2, number2); 86 | ThingSpeak.setField(3, number3); 87 | ThingSpeak.setField(4, number4); 88 | 89 | // figure out the status message 90 | if(number1 > number2){ 91 | myStatus = String("field1 is greater than field2"); 92 | } 93 | else if(number1 < number2){ 94 | myStatus = String("field1 is less than field2"); 95 | } 96 | else{ 97 | myStatus = String("field1 equals field2"); 98 | } 99 | 100 | // set the status 101 | ThingSpeak.setStatus(myStatus); 102 | 103 | // write to the ThingSpeak channel 104 | int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); 105 | if(x == 200){ 106 | Serial.println("Channel update successful."); 107 | } 108 | else{ 109 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 110 | } 111 | 112 | // change the values 113 | number1++; 114 | if(number1 > 99){ 115 | number1 = 0; 116 | } 117 | number2 = random(0,100); 118 | number3 = random(0,100); 119 | number4 = random(0,100); 120 | 121 | delay(20000); // Wait 20 seconds to update the channel again 122 | } 123 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/WriteMultipleFieldsSecure/secrets.h: -------------------------------------------------------------------------------- 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 9 | 10 | // ThingSpeak Certificate Fingerprint, Expiration Date: August 3, 2022 at 8:00:00 AM EST 11 | #define SECRET_SHA1_FINGERPRINT "27 18 92 DD A4 26 C3 07 09 B9 7A E6 C5 21 B9 5B 48 F7 16 E1" 12 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/WriteSingleField/WriteSingleField.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds. 5 | 6 | Hardware: ESP8266 based boards 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires ESP8266WiFi library and ESP8622 board add-on. See https://github.com/esp8266/Arduino for details. 12 | - Select the target hardware from the Tools->Board menu 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #include 27 | #include "secrets.h" 28 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 29 | 30 | char ssid[] = SECRET_SSID; // your network SSID (name) 31 | char pass[] = SECRET_PASS; // your network password 32 | int keyIndex = 0; // your network key Index number (needed only for WEP) 33 | WiFiClient client; 34 | 35 | unsigned long myChannelNumber = SECRET_CH_ID; 36 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 37 | 38 | int number = 0; 39 | 40 | void setup() { 41 | Serial.begin(115200); // Initialize serial 42 | while (!Serial) { 43 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 44 | } 45 | 46 | WiFi.mode(WIFI_STA); 47 | ThingSpeak.begin(client); // Initialize ThingSpeak 48 | } 49 | 50 | void loop() { 51 | 52 | // Connect or reconnect to WiFi 53 | if(WiFi.status() != WL_CONNECTED){ 54 | Serial.print("Attempting to connect to SSID: "); 55 | Serial.println(SECRET_SSID); 56 | while(WiFi.status() != WL_CONNECTED){ 57 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 58 | Serial.print("."); 59 | delay(5000); 60 | } 61 | Serial.println("\nConnected."); 62 | } 63 | 64 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 65 | // pieces of information in a channel. Here, we write to field 1. 66 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 67 | if(x == 200){ 68 | Serial.println("Channel update successful."); 69 | } 70 | else{ 71 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 72 | } 73 | 74 | // change the value 75 | number++; 76 | if(number > 99){ 77 | number = 0; 78 | } 79 | 80 | delay(20000); // Wait 20 seconds to update the channel again 81 | } 82 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/WriteSingleFieldSecure/WriteSingleFieldSecure.ino: -------------------------------------------------------------------------------- 1 | /* 2 | WriteSingleField 3 | 4 | Description: Writes a value to a channel on ThingSpeak every 20 seconds over secured HTTPS connection. 5 | 6 | Hardware: ESP8266 based boards 7 | 8 | !!! IMPORTANT - Modify the secrets.h file for this project with your network connection and ThingSpeak channel details. !!! 9 | 10 | Note: 11 | - Requires ESP8266WiFi library, WiFiClientSecure library and ESP8622 board add-on. See https://github.com/esp8266/Arduino for details. 12 | - Select the target hardware from the Tools->Board menu 13 | - This example is written for a network using WPA encryption. For WEP or WPA, change the WiFi.begin() call accordingly. 14 | 15 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 16 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 17 | 18 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 19 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 20 | 21 | For licensing information, see the accompanying license file. 22 | 23 | Copyright 2020, The MathWorks, Inc. 24 | */ 25 | 26 | #define TS_ENABLE_SSL // For HTTPS SSL connection 27 | 28 | #include 29 | #include 30 | #include "secrets.h" 31 | #include "ThingSpeak.h" // always include thingspeak header file after other header files and custom macros 32 | 33 | char ssid[] = SECRET_SSID; // your network SSID (name) 34 | char pass[] = SECRET_PASS; // your network password 35 | int keyIndex = 0; // your network key Index number (needed only for WEP) 36 | WiFiClientSecure client; 37 | 38 | unsigned long myChannelNumber = SECRET_CH_ID; 39 | const char * myWriteAPIKey = SECRET_WRITE_APIKEY; 40 | 41 | int number = 0; 42 | 43 | // Fingerprint check, make sure that the certificate has not expired. 44 | const char * fingerprint = NULL; // use SECRET_SHA1_FINGERPRINT for fingerprint check 45 | 46 | void setup() { 47 | Serial.begin(115200); // Initialize serial 48 | while (!Serial) { 49 | ; // wait for serial port to connect. Needed for Leonardo native USB port only 50 | } 51 | 52 | WiFi.mode(WIFI_STA); 53 | 54 | if(fingerprint!=NULL){ 55 | client.setFingerprint(fingerprint); 56 | } 57 | else{ 58 | client.setInsecure(); // To perform a simple SSL Encryption 59 | } 60 | 61 | ThingSpeak.begin(client); // Initialize ThingSpeak 62 | } 63 | 64 | void loop() { 65 | 66 | // Connect or reconnect to WiFi 67 | if(WiFi.status() != WL_CONNECTED){ 68 | Serial.print("Attempting to connect to SSID: "); 69 | Serial.println(SECRET_SSID); 70 | while(WiFi.status() != WL_CONNECTED){ 71 | WiFi.begin(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network 72 | Serial.print("."); 73 | delay(5000); 74 | } 75 | Serial.println("\nConnected."); 76 | } 77 | 78 | // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different 79 | // pieces of information in a channel. Here, we write to field 1. 80 | int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey); 81 | if(x == 200){ 82 | Serial.println("Channel update successful."); 83 | } 84 | else{ 85 | Serial.println("Problem updating channel. HTTP error code " + String(x)); 86 | } 87 | 88 | // change the value 89 | number++; 90 | if(number > 99){ 91 | number = 0; 92 | } 93 | 94 | delay(5000); // Wait 20 seconds to update the channel again 95 | } 96 | -------------------------------------------------------------------------------- /examples/ESP8266/program board directly/WriteSingleFieldSecure/secrets.h: -------------------------------------------------------------------------------- 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 9 | 10 | // ThingSpeak Certificate Fingerprint, Expiration Date: August 3, 2022 at 8:00:00 AM EST 11 | #define SECRET_SHA1_FINGERPRINT "27 18 92 DD A4 26 C3 07 09 B9 7A E6 C5 21 B9 5B 48 F7 16 E1" 12 | -------------------------------------------------------------------------------- /examples/ESP8266/via AT commands/ReadField/secrets.h: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /examples/ESP8266/via AT commands/WriteMultipleFields/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/ESP8266/via AT commands/WriteSingleField/secrets.h: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /extras/test/testBegin/testBegin.ino: -------------------------------------------------------------------------------- 1 | #line 2 "testBegin.ino" 2 | /* 3 | testBegin unit test 4 | 5 | Unit Test for the connection through HTTP in the ThingSpeak Communication Library for Arduino 6 | 7 | This test use the ArduinoUnit 2.1.0 unit test framework. Visit https://github.com/mmurdoch/arduinounit to learn more. 8 | 9 | ArduinoUnit does not support ESP8266 or ESP32 and therefor these tests will not compile for those platforms. 10 | 11 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 12 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 13 | 14 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 15 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 16 | 17 | For licensing information, see the accompanying license file. 18 | 19 | Copyright 2020, The MathWorks, Inc. 20 | */ 21 | 22 | //#define USE_WIFI101_SHIELD 23 | //#define USE_ETHERNET_SHIELD 24 | 25 | 26 | #if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) 27 | #error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD" 28 | #endif 29 | 30 | #include 31 | 32 | #if defined(ARDUINO_AVR_YUN) 33 | #include "YunClient.h" 34 | YunClient client; 35 | #else 36 | #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) 37 | // Use WiFi 38 | #include 39 | #include 40 | char ssid[] = ""; // your network SSID (name) 41 | char pass[] = ""; // your network password 42 | int status = WL_IDLE_STATUS; 43 | WiFiClient client; 44 | #elif defined(USE_ETHERNET_SHIELD) 45 | // Use wired ethernet shield 46 | #include 47 | #include 48 | byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 49 | EthernetClient client; 50 | #endif 51 | #endif 52 | 53 | #include // always include thingspeak header file after other header files and custom macros 54 | 55 | #define FIELD1 1 56 | #define WRITE_DELAY_FOR_THINGSPEAK 15000 // Data write limit for a free user (15 sec). 57 | 58 | unsigned long testChannelNumber = 1070863; 59 | const char * testChannelWriteAPIKey = "UI7FSU4O8ZJ5BM8O"; 60 | 61 | test(beginCase) 62 | { 63 | assertTrue(ThingSpeak.begin(client)); 64 | 65 | int val = 25; 66 | 67 | // Always wait to ensure that rate limit isn't hit 68 | delay(WRITE_DELAY_FOR_THINGSPEAK); 69 | assertTrue(ThingSpeak.begin(client)); 70 | assertEqual(TS_OK_SUCCESS, ThingSpeak.writeField(testChannelNumber, FIELD1, val, testChannelWriteAPIKey)); 71 | } 72 | 73 | void setup() 74 | { 75 | Serial.begin(9600); 76 | while(!Serial); // for the Arduino Leonardo/Micro only 77 | Serial.println("Starting test..."); 78 | #ifdef ARDUINO_AVR_YUN 79 | Bridge.begin(); 80 | #else 81 | #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) 82 | WiFi.begin(ssid, pass); 83 | #else 84 | Ethernet.begin(mac); 85 | #endif 86 | #endif 87 | } 88 | 89 | void loop() 90 | { 91 | Test::run(); 92 | } 93 | -------------------------------------------------------------------------------- /extras/test/testSecureConnect/testSecureConnect.ino: -------------------------------------------------------------------------------- 1 | #line 2 "testSecureConnect.ino" 2 | /* 3 | testSecureConnect unit test 4 | 5 | Unit Test for the secure connection through HTTPS in the ThingSpeak Communication Library for Arduino 6 | 7 | This test use the ArduinoUnit 2.1.0 unit test framework. Visit https://github.com/mmurdoch/arduinounit to learn more. 8 | 9 | ArduinoUnit does not support ESP8266 or ESP32 and therefor these tests will not compile for those platforms. 10 | 11 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize, and 12 | analyze live data streams in the cloud. Visit https://www.thingspeak.com to sign up for a free account and create a channel. 13 | 14 | Documentation for the ThingSpeak Communication Library for Arduino is in the README.md folder where the library was installed. 15 | See https://www.mathworks.com/help/thingspeak/index.html for the full ThingSpeak documentation. 16 | 17 | For licensing information, see the accompanying license file. 18 | 19 | Copyright 2020, The MathWorks, Inc. 20 | */ 21 | 22 | //#define USE_WIFI101_SHIELD 23 | //#define USE_ETHERNET_SHIELD 24 | 25 | 26 | #if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) 27 | #error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD" 28 | #endif 29 | 30 | #include 31 | 32 | #if defined(ARDUINO_AVR_YUN) 33 | #include "YunClient.h" 34 | YunClient client; 35 | #else 36 | #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) 37 | // Use WiFi 38 | #include 39 | #include 40 | char ssid[] = ""; // your network SSID (name) 41 | char pass[] = ""; // your network password 42 | int status = WL_IDLE_STATUS; 43 | WiFiSSLClient secureClient; 44 | #elif defined(USE_ETHERNET_SHIELD) 45 | // Use wired ethernet shield 46 | #include 47 | #include 48 | byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 49 | EthernetClient client; 50 | #endif 51 | #endif 52 | 53 | #define TS_ENABLE_SSL 54 | #include // always include thingspeak header file after other header files and custom macros 55 | #define FIELD1 1 56 | #define WRITE_DELAY_FOR_THINGSPEAK 15000 // Data write limit for a free user (15 sec). 57 | 58 | unsigned long testChannelNumber = 1070863; 59 | const char * testChannelWriteAPIKey = "UI7FSU4O8ZJ5BM8O"; 60 | 61 | #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) 62 | test(secureConnectMKR1000Case) 63 | { 64 | assertTrue(ThingSpeak.begin(secureClient)); 65 | 66 | int val = 25; 67 | 68 | // Always wait to ensure that rate limit isn't hit 69 | delay(WRITE_DELAY_FOR_THINGSPEAK); 70 | assertTrue(ThingSpeak.begin(secureClient)); 71 | assertEqual(TS_OK_SUCCESS, ThingSpeak.writeField(testChannelNumber, FIELD1, val, testChannelWriteAPIKey)); 72 | } 73 | #endif 74 | 75 | #if defined(USE_ETHERNET_SHIELD) || defined(ARDUINO_AVR_UNO) 76 | test(secureConnectUnoEthernetCase) 77 | { 78 | assertTrue(ThingSpeak.begin(client)); 79 | 80 | int val = 25; 81 | 82 | // Always wait to ensure that rate limit isn't hit 83 | delay(WRITE_DELAY_FOR_THINGSPEAK); 84 | assertTrue(ThingSpeak.begin(client)); 85 | assertEqual(TS_OK_SUCCESS, ThingSpeak.writeField(testChannelNumber, FIELD1, val, testChannelWriteAPIKey)); 86 | } 87 | #endif 88 | 89 | void setup() 90 | { 91 | Serial.begin(9600); 92 | while(!Serial); // for the Arduino Leonardo/Micro only 93 | Serial.println("Starting test..."); 94 | #ifdef ARDUINO_AVR_YUN 95 | Bridge.begin(); 96 | #else 97 | #if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) 98 | WiFi.begin(ssid, pass); 99 | #else 100 | Ethernet.begin(mac); 101 | #endif 102 | #endif 103 | } 104 | 105 | void loop() 106 | { 107 | Test::run(); 108 | } 109 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ThingSpeak KEYWORD1 2 | begin KEYWORD2 3 | writeField KEYWORD2 4 | setField KEYWORD2 5 | setLatitude KEYWORD2 6 | setLongitude KEYWORD2 7 | setElevation KEYWORD2 8 | setStatus KEYWORD2 9 | setTwitterTweet KEYWORD2 10 | setCreatedAt KEYWORD2 11 | writeRaw KEYWORD2 12 | writeFields KEYWORD2 13 | readFloatField KEYWORD2 14 | readIntField KEYWORD2 15 | readLongField KEYWORD2 16 | readStringField KEYWORD2 17 | readStatus KEYWORD2 18 | readCreatedAt KEYWORD2 19 | readRaw KEYWORD2 20 | getLastReadStatus KEYWORD2 -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ThingSpeak 2 | version=2.1.1 3 | author=MathWorks 4 | maintainer=MathWorks 5 | sentence=ThingSpeak Communication Library for Arduino, ESP8266 & EPS32 6 | paragraph=ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and analyze live data streams in the cloud. 7 | category=Communication 8 | url=https://www.thingspeak.com/ 9 | architectures=avr,esp8266,sam,samd,esp32,megaavr,renesas,renesas_portenta,renesas_uno,rp2040,rp2350 10 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | Copyright :copyright: 2017, The MathWorks, Inc. 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 4. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /src/ThingSpeak.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ThingSpeak Communication Library For Arduino, ESP8266 and ESP32 3 | 4 | ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and 5 | analyze live data streams in the cloud. 6 | 7 | Copyright 2017-2025, The MathWorks, Inc. 8 | 9 | See the accompanying license file for licensing information. 10 | */ 11 | 12 | #include "ThingSpeak.h" 13 | ThingSpeakClass ThingSpeak; 14 | --------------------------------------------------------------------------------