Remote control
Control your device or machine from a Browser. By using server, Automation could be done. If a sensor value exceeds a threshold value, the motor is turned, or other errors, faults or abnormalities are detected. Real-time operation is possible at the time.
<script src="https://unpkg.com/obniz@3.x/obniz.js"></script>
<button id="on">ON</button>
<button id="off">OFF</button>
<script>
const obniz = new Obniz("OBNIZ_ID_HERE", {access_token: "YOUR_TOKEN"});
// Output from IO0 regarding button event
$("#on").click(() => {
obniz.io0.output(true);
})
$("#off").click(() => {
obniz.io0.output(false);
})
</script>
Visualization of acquired values and data<
You can visualize the value and data obtained from the sensor in graphs, charts and maps. Live or Historical view can be easily created.
<script src="https://unpkg.com/obniz@3.x/obniz.js"></script>
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<script>
const obnizdata = [], options = { chart: { type: 'line' }, series: [{ data }] }
const obnizchart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
const obniz = new Obniz("OBNIZ_ID_HERE", {access_token: "YOUR_TOKEN"});
obniz.loop = async () => {
// get IO0 voltage
const voltage = await obniz.ad0.getWait()
// update chart
data.push(voltage)
chart.updateSeries([{ data }])
};
</script>
Image Recognition / AI
By combining it with person detection, object recognition, and sex determination using deep learning such as Tensorflow, advanced alarm systems can be implemented in a short program.
const Obniz = require("obniz");
const cocoSsd = require('@tensorflow-models/coco-ssd');
const obniz = new Obniz("OBNIZ_ID_HERE", {access_token: "YOUR_TOKEN"});
obniz.onconnect = async () => {
// Load the model.
const model = await cocoSsd.load();
// Take a photo
const cam = obniz.wired("ArduCAMMini", { cs:0, mosi:1, miso:2, sclk:3, sda:6, scl:7 });
await cam.startupWait();
const img = await cam.takeWait('1024x768');
// Classify the image.
const predictions = await model.detect(img);
if (predictions[0].class === 'person') {
obniz.display.print("Found Person")
}
}
Data storage
Values and data from sensors can be saved to an internal server or an external database. You can save it to MySQL, for example, or to a Google spreadsheet. You can also perform real-time analytics with AWSKinesis.
const Obniz = require("obniz");
const Logtta_TH = Obniz.getPartsClass('Logtta_TH');
const MYSQL = require('mysql');
const mysql = MYSQL.createConnection();
const obniz = new Obniz("OBNIZ_ID_HERE", {access_token: "YOUR_TOKEN"});
obniz.onconnect = async () => {
await obniz.ble.initWait();
obniz.ble.scan.onfind = async (peripheral) => {
// Connect Logtta BLE Temperature sensor
if (Logtta_TH.isDevice(peripheral)) {
const device = new Logtta_TH(peripheral);
await device.connectWait();
const temperature = await device.getTemperatureWait();
// save to Database
mysql.query('INSERT INTO temps SET ?', {temp: temperature}, function (error, results, fields) {});
}
};
await obniz.ble.scan.startWait();
}
Alert / Notification
We'll send SMS notifications when the sensor value exceeds the threshold, as well as daily email notifications at regular intervals. Send alerts and notifications to email and SMS, such as.
const Obniz = require("obniz");
const { WebClient } = require('@slack/client');
const web = new WebClient("YOUR_SLACK_TOKEN");
const obniz = new Obniz("OBNIZ_ID_HERE", {access_token: "YOUR_TOKEN"});
await obniz.connectWait();
const sens = obniz.wired("HC-SR505", {vcc:0, signal:1, gnd:2});
// Send Slack message when found
sens.onchange = async (val) => {
await web.chat.postMessage({
channel: 'general',
text: `Human Detected at ${new Date()}`
});
}
API integration
You can build powerful IoT systems in the shortest time possible by integrating with AWS, Microsoft Azure, Google Cloud and any web service with REST APIs.
const Obniz = require("obniz");
const Logtta_TH = Obniz.getPartsClass('Logtta_TH');
const kinesis = new require("aws-sdk").Kinesis();
const obniz = new Obniz("OBNIZ_ID_HERE", {access_token: "YOUR_TOKEN"});
obniz.onconnect = async () => {
await obniz.ble.initWait();
obniz.ble.scan.onfind = async (peripheral) => {
// Connect Logtta BLE Temperature sensor
if (Logtta_TH.isDevice(peripheral)) {
const device = new Logtta_TH(peripheral);
await device.connectWait();
const temperature = await device.getTemperatureWait();
// Send to AWS Kinesis
const record = {
Data: JSON.stringify({ temperature }),
PartitionKey: "1",
StreamName: 'your-stream',
};
await kinesis.putRecord(record).promise();
}
};
await obniz.ble.scan.startWait();
}