-
Notifications
You must be signed in to change notification settings - Fork 2
/
Portenta_BLE_Bridge.ino
78 lines (58 loc) · 1.69 KB
/
Portenta_BLE_Bridge.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
74
75
76
77
78
/*
* Upload this sketch to Portenta to use it as a BLE bridge between
* Nicla Sense ME and the Arduino Cloud.
* Nicla Sense ME board needs to run the basic App.ino sketch.
*
* Before uploading this sketch to Portenta:
* - add your Portenta device to Arduino Cloud
* - setup temperature and seconds Things in Arduino Cloud
* - get the THING_ID and copy it in thingProperties.h
* - create a Dashboard in Arduino Cloud, like a live chart of the temperature
*/
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include "thingProperties.h"
#include "Arduino_BHY2Host.h"
Sensor tempSensor(SENSOR_ID_TEMP);
int printTime = 0;
#define DEBUG false
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
while(!Serial) {}
#ifndef TARGET_PORTENTA_H7
Serial.println("Unsupported board!");
while(1);
#endif
#if DEBUG
BHY2Host.debug(Serial);
#endif
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
if (!ArduinoCloud.begin(ArduinoIoTPreferredConnection)) {
Serial.println("ArduinoCloud.begin FAILED!");
}
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
while(!ArduinoCloud.connected()) {
ArduinoCloud.update();
delay(10);
}
Serial.println("Configuring Nicla...");
while (!BHY2Host.begin(false, NICLA_VIA_BLE)) {}
Serial.println("NICLA device found!");
tempSensor.begin();
printTime = millis();
}
void loop() {
BHY2Host.update(100);
if (millis() - printTime > 1000) {
printTime = millis();
seconds = millis()/1000;
temperature = tempSensor.value();
Serial.print("Temp: ");
Serial.println(temperature, 3);
}
ArduinoCloud.update();
}