Skip to content

Commit

Permalink
add sensor tutorial as example #6; harmonize ProductUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
bsatrom committed Dec 7, 2020
1 parent 2bd4987 commit 8f36330
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// "claim" a unique product ID for your device. It could be something as simple as as your email
// address in reverse, such as "com.gmail.smith.lisa.test-device" or "com.outlook.gates.bill.demo"

#define myProductID "org.coca-cola.soda.vending-machine.v2"
#define myProductID "com.your-company.your-name:your_project"
#define myLiveDemo true

// One-time Arduino initialization
Expand Down
4 changes: 2 additions & 2 deletions examples/Example1_NotecardBasics/Example1_NotecardBasics.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
// type of device has embedded the Notecard, and by extension which vendor or customer is in charge
// of "managing" it. In order to set this value, you must first register with notehub.io and
// "claim" a unique product ID for your device. It could be something as simple as as your email
// address in reverse, such as "com.gmail.smith.lisa.test-device" or "com.outlook.gates.bill.demo"
// address in reverse, such as "com.gmail.smith.lisa:test-device" or "com.outlook.gates.bill.demo"

#define myProductID "org.coca-cola.soda.vending-machine.v2"
#define myProductID "com.your-company.your-name:your_project"
Notecard notecard;

// One-time Arduino initialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#define serialDebugOut Serial

// This is the unique Product Identifier for your device.
#define myProductID "org.coca-cola.soda.vending-machine.v2"
#define myProductID "com.your-company.your-name:your_project"
Notecard notecard;

// Button handling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#define serialDebugOut Serial

// This is the unique Product Identifier for your device.
#define myProductID "org.coca-cola.soda.vending-machine.v2"
#define myProductID "com.your-company.your-name:your_project"
Notecard notecard;
#define myLiveDemo true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define serialDebugOut Serial

// This is the unique Product Identifier for your device.
#define myProductID "org.coca-cola.soda.vending-machine.v2"
#define myProductID "com.your-company.your-name:your_project"
Notecard notecard;
#define myLiveDemo true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
// of "managing" it. In order to set this value, you must first register with notehub.io and
// "claim" a unique product ID for your device. It could be something as simple as as your email
// address in reverse, such as "com.gmail.smith.lisa.test-device" or "com.outlook.gates.bill.demo"
#define myProductID "org.coca-cola.soda.vending-machine.v2"
#define myProductID "com.your-company.your-name:your_project"
Notecard notecard;

// A sample binary object, just for binary payload simulation
Expand Down
89 changes: 89 additions & 0 deletions examples/Example6_SensorTutorial/Example6_SensorTutorial.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// Copyright 2019 Blues Inc. All rights reserved.
// Use of this source code is governed by licenses granted by the
// copyright holder including that found in the LICENSE file.
//
// This example contains the complete source for the Sensor Tutorial at dev.blues.io
// https://dev.blues.io/build/tutorials/sensor-tutorial/notecarrier-af/esp32/arduino-wiring/
//
// This tutorial requires an external Adafruit BME680 Sensor.
//

// Include the Arduino library for the Notecard
#include <Notecard.h>

#include <Wire.h>
#include <Adafruit_BME680.h>

Adafruit_BME680 bmeSensor;

//#define serialNotecard Serial1
#define serialDebug Serial

#define productUID "com.your-company.your-name:your_project"
Notecard notecard;

// One-time Arduino initialization
void setup() {
#ifdef serialDebug
delay(2500);
serialDebug.begin(115200);
notecard.setDebugOutputStream(serialDebug);
#endif

// Initialize the physical I/O channel to the Notecard
#ifdef serialNotecard
notecard.begin(serialNotecard, 9600);
#else
Wire.begin();

notecard.begin();
#endif

J *req = notecard.newRequest("hub.set");
JAddStringToObject(req, "product", productUID);
JAddStringToObject(req, "mode", "continuous");
notecard.sendRequest(req);

if (!bmeSensor.begin()) {
serialDebug.println("Could not find a valid BME680 sensor...");
} else {
serialDebug.println("BME680 Connected...");
}

bmeSensor.setTemperatureOversampling(BME680_OS_8X);
bmeSensor.setHumidityOversampling(BME680_OS_2X);
}

void loop() {
if (! bmeSensor.performReading()) {
serialDebug.println("Failed to obtain a reading...");
delay(15000);
return;
}

serialDebug.print("Temperature = ");
serialDebug.print(bmeSensor.temperature);
serialDebug.println(" *C");

serialDebug.print("Humidity = ");
serialDebug.print(bmeSensor.humidity);
serialDebug.println(" %");

J *req = notecard.newRequest("note.add");
if (req != NULL) {
JAddStringToObject(req, "file", "sensors.qo");
JAddBoolToObject(req, "start", true);

J *body = JCreateObject();
if (body != NULL) {
JAddNumberToObject(body, "temp", bmeSensor.temperature);
JAddNumberToObject(body, "humidity", bmeSensor.humidity);
JAddItemToObject(req, "body", body);
}

notecard.sendRequest(req);
}

delay(15000);
}

0 comments on commit 8f36330

Please sign in to comment.