Skip to content

Commit 5df3f11

Browse files
committed
Adding secret file and two other examples
1 parent 87d8871 commit 5df3f11

File tree

7 files changed

+211
-4
lines changed

7 files changed

+211
-4
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,3 @@
3434
*.iml
3535
.idea
3636

37-
//Credentials file
38-
/example/Arduino_nano33_MQTT/arduino_secrets.h

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
This libray allows to connect to dcd hub and update value of thing property provided by property_id.
44

5-
Currently this library uses MQTT interface to connect to the DCD hub and update particular thing property. In future release there will be more functionality added to create a new property or seatch for exising one.
5+
Currently this library uses MQTT interface to connect to the DCD hub and update particular thing property. In future release there will be more functionality added to create a new property or search for exising one.
66

7-
You can find simple example of updating property values from the example provided in the folder.
7+
You can find simple example of updating property values from the example folder provided with the library.
88

99
# Changelog
1010

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// The example uses an arduno sdk for DCD hub to connect and update
2+
// 3-dimensional accelerometer values on thing's property.
3+
//
4+
// In this example, We are using Adafruit_BNO055 driver to derive X, Y, Z co-ordinates within the sensor.
5+
// https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/overview
6+
//
7+
// Once you uploaded the code, You can check live update on your dcd hub dashboard after a successful
8+
// connection here: https://dwd.tudelft.nl/subject.
9+
//
10+
// by Nirav Malsattar <[email protected]>
11+
// https://github.com/datacentricdesign/dcd-sdk-arduino
12+
13+
#include <Wire.h>
14+
#include <Adafruit_Sensor.h> //Adaruit Sensor Library (must to include before BNO055)
15+
#include <Adafruit_BNO055.h> //Adafruit BNO055 Library
16+
#include <utility/imumaths.h> // Algorithm to calculates exact orientation data
17+
18+
#include "arduino_secrets.h" //Include the credentials
19+
#include <dcd_hub_arduino.h> //Include DCD SDK
20+
21+
dcd_hub_arduino dcdHub; //creates a class object from dcd sdk
22+
Adafruit_BNO055 bno = Adafruit_BNO055(55); //Creates class object from BNO Sensor library
23+
24+
void setup() {
25+
//Initialize serial and wait for port to open:
26+
Serial.begin(115200);
27+
while (!Serial) {
28+
; // wait for serial port to connect. Needed for native USB port only
29+
}
30+
31+
// Connects to dcd hub using your secret credential from "arduino_secrets.h"
32+
//{class_object}.connect(SECRET_SSID, SECRET_PASS, THING_ID, THING_TOKEN)
33+
34+
// Make sure you have stored your credentials on "arduino_secrets.h" before running this command
35+
36+
dcdHub.connect(SECRET_SSID, SECRET_PASS, THING_ID, THING_TOKEN, "Arduino Nano 33 IoT");
37+
Serial.println();
38+
39+
/* Initialise the BNO055 sensor */
40+
if (!bno.begin())
41+
{
42+
/* There was a problem detecting the BNO055 ... check your connections */
43+
Serial.print("Ooops, no BNO055 Sensor detected ... Check your wiring or I2C ADDR!");
44+
while (1);
45+
}
46+
47+
delay(1000);
48+
49+
bno.setExtCrystalUse(true);
50+
51+
}
52+
53+
void loop() {
54+
55+
// call keep_alive_mqtt() regularly to avoids being disconnected by the MQTT broker
56+
dcdHub.keep_alive_mqtt();
57+
58+
/* Get a new BNO055 sensor event */
59+
sensors_event_t event;
60+
bno.getEvent(&event);
61+
62+
/* Display the floating point data derived from BNO sensor*/
63+
Serial.print("X: ");
64+
Serial.print(event.orientation.x, 4);
65+
Serial.print("\tY: ");
66+
Serial.print(event.orientation.y, 4);
67+
Serial.print("\tZ: ");
68+
Serial.print(event.orientation.z, 4);
69+
Serial.println("");
70+
71+
float orientationValue[] = {event.orientation.x, event.orientation.y, event.orientation.z};
72+
73+
delay(100);
74+
75+
//call to an update_property object to update property value as an array according to it's "proeprty_id"
76+
//{class_object}.update property (property_id, value[], dimension)
77+
78+
dcdHub.update_property("my-random-property2-563b", orientationValue, 3);
79+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define SECRET_SSID "YOUR WIFI/HOTSPOT SSID"
2+
#define SECRET_PASS "PASSWORD"
3+
4+
#define THING_ID "YOUR THING ID"
5+
#define THING_TOKEN "YOUR THING TOKEN"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define SECRET_SSID "YOUR WIFI/HOTSPOT SSID"
2+
#define SECRET_PASS "PASSWORD"
3+
4+
#define THING_ID "YOUR THING ID"
5+
#define THING_TOKEN "YOUR THING TOKEN"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// The example uses an arduno sdk for DCD hub to connect and update
2+
// Force Sensitive Register (FSR) values on thing's property.
3+
//
4+
// In this example, We are using Adafruit Force Sensitive Register (FSR) to measure the presure on the FSR pad.
5+
// https://learn.adafruit.com/force-sensitive-resistor-fsr
6+
//
7+
// Once you uploaded the code, You can check live update on your dcd hub dashboard after a successful
8+
// connection here: https://dwd.tudelft.nl/subject.
9+
//
10+
// by Nirav Malsattar <[email protected]>
11+
// https://github.com/datacentricdesign/dcd-sdk-arduino
12+
//
13+
// Pin Configuration
14+
// FSR Pin (2nd) - Arduino 3.5v / 5v
15+
// FSR Pin (Any) - Arduino nano A0 with the 3.3KOhm Register connected to the ground (Check the schematic from the link below)
16+
//
17+
// Schematic: https://datacentricdesign.org/docs/2019/04/30/sensors-force
18+
19+
20+
#define PRESSURE_PIN A0
21+
22+
#include "arduino_secrets.h"
23+
#include <dcd_hub_arduino.h>
24+
25+
dcd_hub_arduino dcdHub; //creates a class object from library
26+
27+
int value, prev_value = - 10000; // int values (read from analog port, both the current and the previous)
28+
int deviation = 0; // setting the minimum deviation between the measurements (0 by default)
29+
// up to 512 (although that is pretty useless)
30+
double voltage_value, newton_value; // Converted to Voltage
31+
32+
void setup() {
33+
//Initialize serial and wait for port to open:
34+
Serial.begin(115200);
35+
while (!Serial) {
36+
; // wait for serial port to connect. Needed for native USB port only
37+
}
38+
39+
// Connects to dcd hub using your secret credential from "arduino_secrets.h"
40+
//{class_object}.connect(SECRET_SSID, SECRET_PASS, THING_ID, THING_TOKEN)
41+
42+
// Make sure you have stored your credentials on "arduino_secrets.h" before running this command
43+
44+
dcdHub.connect(SECRET_SSID, SECRET_PASS, THING_ID, THING_TOKEN, "Arduino Nano 33 IoT");
45+
Serial.println();
46+
47+
pinMode(PRESSURE_PIN, INPUT); // setting pinmode to read analog value
48+
49+
deviation = 10; // since there's a bit of a drift in the values if you put the same pressure over a certain period
50+
// we ignore a divergence of around 1 percent around the previous value.
51+
}
52+
53+
// This is based on a 3.3kΩ resistor being used, with weights on the center that do not linger more than 10 seconds
54+
// For situations that deviate from this, accuracy can be lost.
55+
double convert_to_newtons( double voltage)
56+
{
57+
/* General fitting model Exp2:
58+
f(x) = a*exp(b*x) + c*exp(d*x)
59+
Coefficients (with 95% confidence bounds):
60+
a = 0.01419 (0.01163, 0.01676)
61+
b = 0.9523 (0.8922, 1.012)
62+
c = -0.01461 (-0.02317, -0.006043)
63+
d = -2.231 (-6.605, 2.142)
64+
Goodness of fit:
65+
SSE: 7.906e-06
66+
R-square: 0.9999
67+
Adjusted R-square: 0.9997
68+
RMSE: 0.001988
69+
*/
70+
double a = 0.01419 ;
71+
double b = 0.9523;
72+
double c = -0.01461;
73+
double d = -2.231;
74+
75+
return( (a*exp(b*voltage) + c*exp(d* voltage)) * 9.81 ); // the result of the fit is in KgF to convert to newton we simply
76+
// multiply by 9.81, if you want data in KgF, remove the final multiplication!
77+
}
78+
79+
80+
void loop() {
81+
82+
// call keep_alive_mqtt() regularly to avoids being disconnected by the MQTT broker
83+
dcdHub.keep_alive_mqtt();
84+
85+
delay(100); // Here we can set the sampling rate, right now 10 Hz
86+
value = analogRead(PRESSURE_PIN); // reading our analog voltage, careful we only have 10 bit resolution so each
87+
// measurement step is only 5V ÷ 1024, so our result will be 0 - 1023
88+
89+
// if value is within the range of [ previous - σ , previous + σ], ignore it (if value is relatively the same)
90+
// this will help with having data ocuppy your buffer that is not a significant deviation.
91+
if( value >= (prev_value - deviation) && value <= (prev_value + deviation) )
92+
return;
93+
94+
voltage_value = double((value*5)) / 1023; // converting to voltage [ 0, 5] v.
95+
newton_value = convert_to_newtons(voltage_value); // getting actual force value (careful using this, accuracy may not be ideal)
96+
// sensitivity after 1Kgf and before 0.06kgf is limited, you can lower the deviation
97+
// for some improvements
98+
Serial.print("Pressure: ");
99+
Serial.print(value);
100+
Serial.print(" (0 - 1023) steps, ");
101+
Serial.print(voltage_value);
102+
Serial.print(" (v), ");
103+
Serial.print(newton_value);
104+
Serial.println(" N.");
105+
106+
prev_value = value;
107+
108+
// Some random 1D, 2D, 3D values to upload on the hub. Later, you can replace these with your sensors value.
109+
float forceValue[] = {newton_value};
110+
111+
//call to an update_property object to update property value as an array according to it's "proeprty_id"
112+
//{class_object}.update property (property_id, value[], dimension)
113+
114+
dcdHub.update_property("random-02d3",forceValue, 1);
115+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define SECRET_SSID "YOUR WIFI/HOTSPOT SSID"
2+
#define SECRET_PASS "PASSWORD"
3+
4+
#define THING_ID "YOUR THING ID"
5+
#define THING_TOKEN "YOUR THING TOKEN"

0 commit comments

Comments
 (0)