-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathArduinoIoTCloud-Notecard.ino
73 lines (59 loc) · 2.21 KB
/
ArduinoIoTCloud-Notecard.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
This sketch demonstrates how to exchange data between your board and the
Arduino IoT Cloud, while using the Notecard for wireless communication.
* Connect a potentiometer (or other analog sensor) to A0.
* When the potentiometer (or sensor) value changes the data is sent to the Cloud.
* When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF.
IMPORTANT:
This sketch works with any Wi-Fi, Cellular, LoRa or Satellite enabled Notecard.
The full list of compatible boards can be found here:
- https://github.com/arduino-libraries/ArduinoIoTCloud#what
*/
#include <Notecard.h>
#include "thingProperties.h"
#if !defined(LED_BUILTIN) && !defined(ARDUINO_NANO_ESP32)
static int const LED_BUILTIN = 2;
#endif
/*
* Choose an interrupt capable pin to reduce polling and improve
* the overall responsiveness of the ArduinoIoTCloud library
*/
// #define ATTN_PIN 9
void setup() {
/* Initialize serial and wait up to 5 seconds for port to open */
Serial.begin(9600);
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
/* Set the debug message level:
* - DBG_ERROR: Only show error messages
* - DBG_WARNING: Show warning and error messages
* - DBG_INFO: Show info, warning, and error messages
* - DBG_DEBUG: Show debug, info, warning, and error messages
* - DBG_VERBOSE: Show all messages
*/
setDebugMessageLevel(DBG_INFO);
/* Configure LED pin as an output */
pinMode(LED_BUILTIN, OUTPUT);
/* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */
initProperties();
/* Initialize Arduino IoT Cloud library */
#ifndef ATTN_PIN
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
ArduinoCloud.setNotecardPollingInterval(3000); // default: 1000ms, min: 250ms
#else
ArduinoCloud.begin(ArduinoIoTPreferredConnection, ATTN_PIN);
#endif
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
potentiometer = analogRead(A0);
seconds = millis() / 1000;
}
/*
* 'onLedChange' is called when the "led" property of your Thing changes
*/
void onLedChange() {
Serial.print("LED set to ");
Serial.println(led);
digitalWrite(LED_BUILTIN, led);
}