You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#pragma message "PRODUCT_UID is not defined in this example. Please ensure your Notecard has a product identifier set before running this example or define it in code here. More details at https://dev.blues.io/tools-and-sdks/samples/product-uid"
49
48
#endif
50
49
@@ -55,6 +54,7 @@ Notecard notecard;
55
54
voidsetup()
56
55
{
57
56
57
+
#ifdef usbSerial
58
58
// Set up for debug output. If you open Arduino's serial terminal window, you'll be able to
59
59
// watch JSON objects being transferred to and from the Notecard for each request. On most
60
60
// Arduino devices, Arduino's serial debug output is on the "Serial" device at 115200.
@@ -63,55 +63,63 @@ void setup()
63
63
// Note that the initial 2.5s delay is required by some Arduino cards before debug
64
64
// UART output can be successfully displayed in the Arduino IDE, including the
65
65
// Adafruit Feather nRF52840 Express.
66
-
#ifdef usbSerial
67
-
delay(2500);
68
-
usbSerial.begin(115200);
69
66
notecard.setDebugOutputStream(usbSerial);
67
+
usbSerial.begin(9600);
68
+
constsize_t start_wait_ms = millis();
69
+
while (!usbSerial && ((millis() - start_wait_ms) < 5000));
70
+
Serial.println("Serial READY");
70
71
#endif
71
72
72
73
// Initialize the physical I/O channel to the Notecard
73
74
#ifdef txRxPinsSerial
74
75
notecard.begin(txRxPinsSerial, 9600);
75
76
#else
76
-
Wire.begin();
77
-
78
77
notecard.begin();
78
+
Serial.println("1");
79
79
#endif
80
80
81
81
// "newRequest()" uses the bundled "J" json package to allocate a "req", which is a JSON object
82
82
// for the request to which we will then add Request arguments. The function allocates a "req"
83
83
// request structure using malloc() and initializes its "req" field with the type of request.
84
84
J *req = notecard.newRequest("hub.set");
85
-
86
-
// This command (required) causes the data to be delivered to the Project on notehub.io that has claimed
87
-
// this Product ID. (see above)
88
-
if (myProductID[0]) {
89
-
JAddStringToObject(req, "product", myProductID);
85
+
Serial.println("2");
86
+
if (req) {
87
+
// This command (required) causes the data to be delivered to the Project on notehub.io that has claimed
88
+
// this Product ID. (see above)
89
+
if (myProductID[0]) {
90
+
JAddStringToObject(req, "product", myProductID);
91
+
Serial.println("3");
92
+
}
93
+
// This command determines how often the Notecard connects to the service. If "continuous" the Notecard
94
+
// immediately establishes a session with the service at notehub.io, and keeps it active continuously.
95
+
// Because of the power requirements of a continuous connection, a battery powered device would instead
96
+
// only sample its sensors occasionally, and would only upload to the service on a periodic basis.
97
+
JAddStringToObject(req, "mode", "continuous");
98
+
Serial.println("4");
99
+
100
+
// Issue the request, telling the Notecard how and how often to access the service.
101
+
// This results in a JSON message to Notecard formatted like:
102
+
// { "req" : "service.set",
103
+
// "product" : myProductID,
104
+
// "mode" : "continuous"
105
+
// }
106
+
// Note that sendRequest() always uses free() to release the request data structure, and it
107
+
// returns "true" if success and "false" if there is any failure.
108
+
notecard.sendRequest(req);
109
+
Serial.println("5");
90
110
}
91
-
// This command determines how often the Notecard connects to the service. If "continuous" the Notecard
92
-
// immediately establishes a session with the service at notehub.io, and keeps it active continuously.
93
-
// Because of the power requirements of a continuous connection, a battery powered device would instead
94
-
// only sample its sensors occasionally, and would only upload to the service on a periodic basis.
95
-
JAddStringToObject(req, "mode", "continuous");
96
-
97
-
// Issue the request, telling the Notecard how and how often to access the service.
98
-
// This results in a JSON message to Notecard formatted like:
99
-
// { "req" : "service.set",
100
-
// "product" : myProductID,
101
-
// "mode" : "continuous"
102
-
// }
103
-
// Note that sendRequest() always uses free() to release the request data structure, and it
104
-
// returns "true" if success and "false" if there is any failure.
105
-
notecard.sendRequest(req);
111
+
106
112
}
107
113
108
114
// In the Arduino main loop which is called repeatedly, add outbound data every 15 seconds
109
115
voidloop()
110
116
{
117
+
Serial.println("Begin `loop`");
111
118
112
119
// Count the simulated measurements that we send to the cloud, and stop the demo before long.
0 commit comments