SlideShare a Scribd company logo
IoT: Internet of Things
There are many home automation solutions and Internet-of-
Things (IoT) gadgets on the market, which are all useful on
their own. They come with their own way on how to setup and
configure devices and are perfect for their intended use
cases.
The problem with all of these systems and devices is that
these use cases are defined by the manufacturer - but as a
user, you will quickly come up with wishes that are not
supported out of the box or which require interaction
between the different systems.
OpenHAB on pcDuino
openHAB
openHAB
pcDuino
pcDuino is a family of single board computers that runs
linux/androids or windows (on some models) and and is
compatible with Arduino ecosystem.
pcDuino FamilypcDuino2 pcDuino3 pcDuino8 pcDuino Acadia
pcDuino
Canyonlands
CPU
Allwinner A10
1GHz ARM Cortex
A8
Allwinner A20, 1GHz,
ARM Cortex A7 Dual
Core
Allwinner H8
2GHz, 8-Core
Cortex-A7
Freescale Quad
ARM Cortex A9
@1.2GHz
Intel ATOM Z3735F
Quad Core 1.33-
1.88GHz
GPU
OpenGL
ES2.0OpenVG 1.1
Mali 400 core
OpenGL
ES2.0OpenVG 1.1
Mali 400 core
PowerVR SG544
@720MHz
OpenGL/ES 2 x 3D
accelerator with
OpenCL and
OpenVG
Intel HD Graphics,
311-645MHz
DRAM 1GB 1GB 1GB 1GB 2GB
Storage
2GB Flash (4GB
after
2/1/2014)microSD
card (TF) slot for up
to 32GB
4GB Flash
microSD card (TF)
slot for up to 32GB
microSD card slot for
up to 32GB
microSD card slot for
up to 128GB
32GB emmC
Video HDMI HDMI HDMI HDMI HDMI
OS Support
•Lbuntu 12.04
•Android
•Lbuntu 12.04
•Android
Linux
Android
Linux
Android
Windows 8.1 with
bing
Android
Wndows 10
Extension Interface
Arduino (TM)
Headers
Arduino (TM)
Headers
Arduino (TM)
Headers
Arduino (TM)
Headers
NetworkInterface
•10/100Mbps RJ45
•USB WiFi extension
•10/100Mbps RJ45
•WiFi
•Gbits RJ45 Gbits RJ45 WiFi
Bluetooth
Power 5V, 2000mA 5V, 2000mA 5V, 2000mA 5V, 2000mA 5V, 3000mA
IoT with openHAB on pcDuino3B
pcDuino3B hardware
interfaces
openHAB kit
How to access pcDuino without
HDMI monitor
 Use a TTL UART USB Debugger
 http://store.cutedigi.com/serial-debug-cable-with-
ft232-for-pcduino-raspberry-pi/
 Install Driver on MAC
 http://www.ftdichip.com/Support/Documents/AppNotes/AN_134_FTDI_Dr
ivers_Installation_Guide_for_MAC_OSX.pdf
 Use PuTTY on Windows
 Serial port: 115200
How to access pcDuino
without HDMI monitor
TX-RX
RX-TX
GND-GND
How to access pcDuino
without HDMI monitor
How to access pcDuino
without HDMI monitor
Install OpenHAB on pcDuino
$sudo apt-get install git
$sudo mkdir /opt/openhab
$cd /opt/openhab
$sudo wget
https://github.com/openhab/openhab/releases/download/v1.6.2/distrib
ution-1.6.2-runtime.zip
$sudo unzip distribution-1.6.2-runtime.zip
$cd addons
$sudo wget
https://github.com/openhab/openhab/releases/download/v1.6.2/distrib
ution-1.6.2-addons.zip
$sudo unzip distribution-1.6.2-addons.zip
$cd ..
$sudo wget
https://github.com/openhab/openhab/releases/download/v1.6.2/distrib
ution-1.6.2-demo-configuration.zip
$sudo unzip distribution-1.6.2-demo-configuration.zip
$sudo cp configurations/openhab_default.cfg
configurations/openhab.cfg
How to enable security in OpenHAB
The way to enable security in OpenHAB is to edit the file named
openhab.cfg. Look for the line starts with ‘security:option=’.
If we do ‘security:option=EXTERNAL’, it means that only when we
try to connect to the OpenHAB server from external network, i.e.,
Internet, it will ask for username/password. It will not ask for
credentials.
If we do ‘security:option=ON’, it will always ask for
username/password.
Once the security is turned on, we can add the username and
password to the file user.cfg, for example,
Username password
ben=password1
scott=password2
Use an image with openHAB
preinstalled
 You can use an image with openHAB
preinstalled.
 Please download it from:
 http://www.linksprite.com/?page_id=1289
 The username and password for the
openHAB is
 Username: patrick
 Password: ivpcduino
Web Interface
The URL should be: http://xxx:8080/openhab.app?sitemap=demo
Where xxx is the local IP address of the pcDuino3B.
iOS APP
Bluetooth 4.0 Point to
Point
• Before we configure the openHAB, lets prepare
a pair of BLE shield and configure one of them
to be host and the other to be slave.
• Baud rate 9600
• AT+ROLE? To check role
• AT+ROLE0 to set to slave
• AT+ROLE1 to set to Host
• The role will stay after power cycle
• We may need to do AT+RENEW to clear all
previous settings
• After set role, they will automatically pair
Bluetooth 4.0 Point to
Point
• When we configure the
BLE module, we should
jump the UART of the BLE
module to softserial of
Arduino (D2,D3)
• Load the script shown in
next slides
• Open serial terminal
from Arduino IDE and
enter ‘AT+RENEW’ and
then ‘AT+ROLE1’ to set
host, and ‘AT+ROLE0’
to set slave.
Bluetooth 4.0 Point to
Point
#include <SoftwareSerial.h>
#define RxD 2
#define TxD 3
SoftwareSerial mySerial(RxD,TxD);
void setup()
{
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
mySerial.begin(9600); // the ble4.0 baud rate
Serial.begin(9600); // the terminal baud rate
}
void loop()
{
if(Serial.available())
{
mySerial.print((char)Serial.read());
}
if(mySerial.available())
{
Serial.print((char)mySerial.read());
}
}
Load this script to
Arduino, and then use
serial terminal to
enter AT commands to
configure the BLE
shields
openHAB server
• Install the BLE
with host role
to pcDuino3B
• Move the switch
on the BLE
shield to 3.3V
as pcDuino3B is
3.3V
• Jump the UART
to D0 and D1 as
shown in
picture
Remote Sensor Node
• Install the BLE with
slave role to pcDuino3B
• Move the switch on the
BLE shield to 5 as
Arduino 5V
• Jump the UART to D6 and
D7 as shown in the
picture
• The door sensor is
connected to D8 and GND.
• The LED is connected to
D13 and GND as shown in
the picture.
• Load the sensor code
Sensor Arduino Code
#include <SoftwareSerial.h>
#define RxD 6
#define TxD 7
SoftwareSerial mySerial(RxD,TxD);
char dat;
int i,flag=1;
void setup()
{
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(13,OUTPUT);
pinMode(8,INPUT);
digitalWrite(8,HIGH);
mySerial.begin(9600); // the
ble4.0 baud rate
Serial.begin(9600); // the
terminal baud rate
}
Sensor Arduino Code
void loop()
{
if(Serial.available())
{
mySerial.print((char)Serial.read());
}
if(mySerial.available())
{
dat = char(mySerial.read());
Serial.print(dat);
if(dat == 'S') i++;
if(i%2) digitalWrite(13,LOW);
else digitalWrite(13,HIGH);
}
if( (digitalRead(8)==1)&&(flag==1))
{
flag = 0 ;
mySerial.write("123rn");
Serial.write("123rn");
}
if( (digitalRead(8)==0)&&(flag==0))
{
flag =1 ;
mySerial.write("321rn");
Serial.write("321rn");
}
}
openHAB items and bindings
To add a device to OpenHAB, we need to
configure four files:
/configurations/openhab.cfg
/configurations/items
/configurations/sitemap
/configurations/rules/
/configurations/openhab.cfg
################################### MQTT Transport
#########################################
#
mqtt:mymosquitto.url=tcp://localhost:1883
mqtt:mymosquitto.qos=0
mqtt:mymosquitto.retain=true
mqtt:mymosquitto.async=true
/configurations/items/demo.
items:
Number itm_garage_dist "Garage Dist [%.1f Inch]" (ALL)
{mqtt="<[mymosquitto:4032:state:default]"}
Contact itm_my_gar_door "Garage Door Status
[MAP(en.map):%s]" <garage> (ALL)
/configurations/sitemap/dem
o.sitemap:
Frame label="Garage"
{
Text item=itm_my_gar_door label="Garage Door Status
[%s]"
}
/configurations/rules/:
rule "Convert Door"
when
Item itm_garage_dist received update
then
if(itm_garage_dist.state < 19)
{
itm_my_gar_door.state = OPEN
}
else
{
itm_my_gar_door.state = CLOSED
}
end
Install MQTT broker “Mosquitto”
on pcDuino3/3B for OpenHAB
This MQTT broker bridges the data sent from
Arduino sensor in the field to the OpenHAB’s MQTT
server.
Arduino sensors in the field can send back data in
any format to pcDuino. We can use Arduino-style
programming on pcDuino to receive the data, and
send the data to TCP port 10000. This MQTT broker
will listen to port 10000 and converts the data to
MQTT protocol. Then send that data to the MQTT
server in OpenHAB.
Install Paho MQTT
$sudo apt-get update
$sudo apt-get install mosquitto mosquitto-
clients python-mosquitto
$sudo apt-get install python-pip
$sudo pip install paho-mqtt
Sample Script (Not we will use
today)
import socket
import sys
import paho.mqtt.publish as publish
publish.single("4032",
"05",hostname="192.168.1.39")
Actual MQTT agent
import socket
import sys
import paho.mqtt.publish as publish
import paho.mqtt.client as mqtt
import serial
with open("/sys/devices/virtual/misc/gpio/mode/gpio0",'w') as UART_RX:
UART_RX.write('3')
with open("/sys/devices/virtual/misc/gpio/mode/gpio1",'w') as UART_TX:
UART_TX.write('3')
myport=serial.Serial('/dev/ttyS1',9600,timeout=20)
myport.write('test')
###
Actual MQTT agent
client_connect=0
##
def on_connect(mqttc, obj, flags, rc):
print("rc: "+str(rc))
def on_message(mqttc, obj, msg):
#if client_connect==1:
myport.write('S')
#print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))
#connection.send(msg.topic+" "+str(msg.payload))
def on_publish(mqttc, obj, mid):
print("mid: "+str(mid))
def on_subscribe(mqttc, obj, mid, granted_qos):
print("Subscribed: "+str(mid)+" "+str(granted_qos))
def on_log(mqttc, obj, level, string):
print(string)
Actual MQTT agent
### The following for TCP/IP from Arduino-style part
#############
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# Bind the socket to the port
server_address = ('localhost', 10000)
print >>sys.stderr, 'starting up on %s port %s' %
server_address
sock.bind(server_address)
# Listen for incoming connections
sock.listen(1)
Actual MQTT agent
################ The following for subscribing to MQTT
##############
mqttc = mqtt.Client()
mqttc.on_message = on_message
mqttc.on_connect = on_connect
mqttc.on_publish = on_publish
mqttc.on_subscribe = on_subscribe
mqttc.connect("localhost", 1883, 60)
### Subscribe to topic '4033', which is the ID of the
relay of garage
mqttc.subscribe("4033", 0)
mqttc.loop_start()
Actual MQTT agent
while True:
# Wait for a connection
#print >>sys.stderr, 'waiting for a connection'
#connection, client_address = sock.accept()
#client_connect=1
try:
#print >>sys.stderr, 'connection from', client_address
# Receive the data in small chunks and retransmit it
while True:
#connection.send('Hello world')
ble_data = myport.readline()
if len(ble_data)>0:
print(ble_data)
#data = connection.recv(3)
#print(data)
#if len(data)==0:
#connection.close()
#break
if "test" in ble_data :
print('okay')
if "321" in ble_data:
print >>sys.stderr, 'publish 0'
publish.single("3032", "0",hostname="localhost")
if "123" in ble_data:
print >>sys.stderr, 'publish 1'
publish.single("3032", "1",hostname="localhost")
except KeyboardInterrupt:
# Clean up the connection
#connection.close()
sys.exit(1)
Kick off MQTT agent
 After the openHAB server starts up,
run python MQTT agent by typing:
 sudo python ./mqtt_pubish.py
 Then we can control the LED and see
the status of door sensor on the
web browse r and iOS app
Seed funding and incubator
program
 pcDuino works with LaunchHill to
provide seed funding and incubator
space in Shenzhen, China to help
makers launch their own businesses.
 Inquiries can be made to:
harry.yu@launchhill.com.
Connect with pcDuino
Facebook.com/linksprit
e

More Related Content

PPTX
pcDuino Presentation at SparkFun
PPTX
Scratch pcduino
PPTX
pcDuino tech talk at Carnegie Mellon University 10/14/2014
PPTX
Innovation with pcDuino
PPTX
Introduction to pcDuino
PPTX
Open Source Home Automation with LinkSprite.IO
PPTX
Maker Movement
PDF
Cassiopeia Ltd - ESP8266+Arduino workshop
pcDuino Presentation at SparkFun
Scratch pcduino
pcDuino tech talk at Carnegie Mellon University 10/14/2014
Innovation with pcDuino
Introduction to pcDuino
Open Source Home Automation with LinkSprite.IO
Maker Movement
Cassiopeia Ltd - ESP8266+Arduino workshop

What's hot (18)

PPTX
[5]投影片 futurewad樹莓派研習會 141218
PDF
Esp8266 basics
PPTX
Remote tanklevelmonitor
PDF
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
PDF
Rdl esp32 development board trainer kit
PPTX
Esp8266 - Intro for dummies
PPTX
Remote temperature monitor (DHT11)
PDF
Adafruit Huzzah Esp8266 WiFi Board
PPTX
IOT Talking to Webserver - how to
PPTX
Esp8266 NodeMCU
PDF
Linux+sensor+device-tree+shell=IoT !
PDF
Gnu linux on arm for $50 - $100
PDF
Interacting with Intel Edison
PDF
NodeMCU ESP8266 workshop 1
PPTX
Arduino 習作工坊 - Lesson 1 燈光之夜
PDF
lwM2M OTA for ESP8266
PPTX
IoT Hands-On-Lab, KINGS, 2019
PDF
How to Install ESP8266 WiFi Web Server using Arduino IDE
[5]投影片 futurewad樹莓派研習會 141218
Esp8266 basics
Remote tanklevelmonitor
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
Rdl esp32 development board trainer kit
Esp8266 - Intro for dummies
Remote temperature monitor (DHT11)
Adafruit Huzzah Esp8266 WiFi Board
IOT Talking to Webserver - how to
Esp8266 NodeMCU
Linux+sensor+device-tree+shell=IoT !
Gnu linux on arm for $50 - $100
Interacting with Intel Edison
NodeMCU ESP8266 workshop 1
Arduino 習作工坊 - Lesson 1 燈光之夜
lwM2M OTA for ESP8266
IoT Hands-On-Lab, KINGS, 2019
How to Install ESP8266 WiFi Web Server using Arduino IDE
Ad

Similar to IoT with openHAB on pcDuino3B (20)

PPTX
Getting started with Intel IoT Developer Kit
PPTX
Lab Handson: Power your Creations with Intel Edison!
PDF
DeviceHub - First steps using Intel Edison
PDF
#Include os - From bootloader to REST API with the new C++
PPTX
Attendance system using MYSQL with Raspberry pi and RFID-RC522
PPTX
Using arduino and raspberry pi for internet of things
PDF
Advanced View Arduino Projects List - Use Arduino for Projects-2.pdf
PDF
Esp8266 v12
PDF
ESP32 WiFi & Bluetooth Module - Getting Started Guide
PPT
Basic Linux kernel
PPTX
Tac Presentation October 72014- Raspberry PI
PPTX
Starting Raspberry Pi
PDF
មេរៀនទីd៥ conneeeection with Arduino .pdf
PDF
Command Your IoT Projects from the Terminal
PDF
CNC 3-Axis Stepper Motor Shield
PDF
9 creating cent_os 7_mages_for_dpdk_training
PPTX
IoT on Raspberry Pi
PDF
How To Electrocute Yourself using the Internet
ODP
Multipilot pres-ufficiale last 2
PPT
XBee and RFID
Getting started with Intel IoT Developer Kit
Lab Handson: Power your Creations with Intel Edison!
DeviceHub - First steps using Intel Edison
#Include os - From bootloader to REST API with the new C++
Attendance system using MYSQL with Raspberry pi and RFID-RC522
Using arduino and raspberry pi for internet of things
Advanced View Arduino Projects List - Use Arduino for Projects-2.pdf
Esp8266 v12
ESP32 WiFi & Bluetooth Module - Getting Started Guide
Basic Linux kernel
Tac Presentation October 72014- Raspberry PI
Starting Raspberry Pi
មេរៀនទីd៥ conneeeection with Arduino .pdf
Command Your IoT Projects from the Terminal
CNC 3-Axis Stepper Motor Shield
9 creating cent_os 7_mages_for_dpdk_training
IoT on Raspberry Pi
How To Electrocute Yourself using the Internet
Multipilot pres-ufficiale last 2
XBee and RFID
Ad

Recently uploaded (20)

PPTX
artificial intelligence overview of it and more
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PPTX
Power Point - Lesson 3_2.pptx grad school presentation
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPTX
SAP Ariba Sourcing PPT for learning material
PPTX
innovation process that make everything different.pptx
PPTX
Funds Management Learning Material for Beg
PPTX
Introduction to Information and Communication Technology
PPTX
E -tech empowerment technologies PowerPoint
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
Introduction to the IoT system, how the IoT system works
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
artificial intelligence overview of it and more
Unit-1 introduction to cyber security discuss about how to secure a system
Design_with_Watersergyerge45hrbgre4top (1).ppt
RPKI Status Update, presented by Makito Lay at IDNOG 10
Introuction about ICD -10 and ICD-11 PPT.pptx
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Power Point - Lesson 3_2.pptx grad school presentation
Decoding a Decade: 10 Years of Applied CTI Discipline
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
SAP Ariba Sourcing PPT for learning material
innovation process that make everything different.pptx
Funds Management Learning Material for Beg
Introduction to Information and Communication Technology
E -tech empowerment technologies PowerPoint
Job_Card_System_Styled_lorem_ipsum_.pptx
Introduction to the IoT system, how the IoT system works
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Slides PDF The World Game (s) Eco Economic Epochs.pdf
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...

IoT with openHAB on pcDuino3B

  • 1. IoT: Internet of Things There are many home automation solutions and Internet-of- Things (IoT) gadgets on the market, which are all useful on their own. They come with their own way on how to setup and configure devices and are perfect for their intended use cases. The problem with all of these systems and devices is that these use cases are defined by the manufacturer - but as a user, you will quickly come up with wishes that are not supported out of the box or which require interaction between the different systems.
  • 5. pcDuino pcDuino is a family of single board computers that runs linux/androids or windows (on some models) and and is compatible with Arduino ecosystem.
  • 6. pcDuino FamilypcDuino2 pcDuino3 pcDuino8 pcDuino Acadia pcDuino Canyonlands CPU Allwinner A10 1GHz ARM Cortex A8 Allwinner A20, 1GHz, ARM Cortex A7 Dual Core Allwinner H8 2GHz, 8-Core Cortex-A7 Freescale Quad ARM Cortex A9 @1.2GHz Intel ATOM Z3735F Quad Core 1.33- 1.88GHz GPU OpenGL ES2.0OpenVG 1.1 Mali 400 core OpenGL ES2.0OpenVG 1.1 Mali 400 core PowerVR SG544 @720MHz OpenGL/ES 2 x 3D accelerator with OpenCL and OpenVG Intel HD Graphics, 311-645MHz DRAM 1GB 1GB 1GB 1GB 2GB Storage 2GB Flash (4GB after 2/1/2014)microSD card (TF) slot for up to 32GB 4GB Flash microSD card (TF) slot for up to 32GB microSD card slot for up to 32GB microSD card slot for up to 128GB 32GB emmC Video HDMI HDMI HDMI HDMI HDMI OS Support •Lbuntu 12.04 •Android •Lbuntu 12.04 •Android Linux Android Linux Android Windows 8.1 with bing Android Wndows 10 Extension Interface Arduino (TM) Headers Arduino (TM) Headers Arduino (TM) Headers Arduino (TM) Headers NetworkInterface •10/100Mbps RJ45 •USB WiFi extension •10/100Mbps RJ45 •WiFi •Gbits RJ45 Gbits RJ45 WiFi Bluetooth Power 5V, 2000mA 5V, 2000mA 5V, 2000mA 5V, 2000mA 5V, 3000mA
  • 10. How to access pcDuino without HDMI monitor  Use a TTL UART USB Debugger  http://store.cutedigi.com/serial-debug-cable-with- ft232-for-pcduino-raspberry-pi/  Install Driver on MAC  http://www.ftdichip.com/Support/Documents/AppNotes/AN_134_FTDI_Dr ivers_Installation_Guide_for_MAC_OSX.pdf  Use PuTTY on Windows  Serial port: 115200
  • 11. How to access pcDuino without HDMI monitor TX-RX RX-TX GND-GND
  • 12. How to access pcDuino without HDMI monitor
  • 13. How to access pcDuino without HDMI monitor
  • 14. Install OpenHAB on pcDuino $sudo apt-get install git $sudo mkdir /opt/openhab $cd /opt/openhab $sudo wget https://github.com/openhab/openhab/releases/download/v1.6.2/distrib ution-1.6.2-runtime.zip $sudo unzip distribution-1.6.2-runtime.zip $cd addons $sudo wget https://github.com/openhab/openhab/releases/download/v1.6.2/distrib ution-1.6.2-addons.zip $sudo unzip distribution-1.6.2-addons.zip $cd .. $sudo wget https://github.com/openhab/openhab/releases/download/v1.6.2/distrib ution-1.6.2-demo-configuration.zip $sudo unzip distribution-1.6.2-demo-configuration.zip $sudo cp configurations/openhab_default.cfg configurations/openhab.cfg
  • 15. How to enable security in OpenHAB The way to enable security in OpenHAB is to edit the file named openhab.cfg. Look for the line starts with ‘security:option=’. If we do ‘security:option=EXTERNAL’, it means that only when we try to connect to the OpenHAB server from external network, i.e., Internet, it will ask for username/password. It will not ask for credentials. If we do ‘security:option=ON’, it will always ask for username/password. Once the security is turned on, we can add the username and password to the file user.cfg, for example, Username password ben=password1 scott=password2
  • 16. Use an image with openHAB preinstalled  You can use an image with openHAB preinstalled.  Please download it from:  http://www.linksprite.com/?page_id=1289  The username and password for the openHAB is  Username: patrick  Password: ivpcduino
  • 17. Web Interface The URL should be: http://xxx:8080/openhab.app?sitemap=demo Where xxx is the local IP address of the pcDuino3B.
  • 19. Bluetooth 4.0 Point to Point • Before we configure the openHAB, lets prepare a pair of BLE shield and configure one of them to be host and the other to be slave. • Baud rate 9600 • AT+ROLE? To check role • AT+ROLE0 to set to slave • AT+ROLE1 to set to Host • The role will stay after power cycle • We may need to do AT+RENEW to clear all previous settings • After set role, they will automatically pair
  • 20. Bluetooth 4.0 Point to Point • When we configure the BLE module, we should jump the UART of the BLE module to softserial of Arduino (D2,D3) • Load the script shown in next slides • Open serial terminal from Arduino IDE and enter ‘AT+RENEW’ and then ‘AT+ROLE1’ to set host, and ‘AT+ROLE0’ to set slave.
  • 21. Bluetooth 4.0 Point to Point #include <SoftwareSerial.h> #define RxD 2 #define TxD 3 SoftwareSerial mySerial(RxD,TxD); void setup() { pinMode(RxD, INPUT); pinMode(TxD, OUTPUT); mySerial.begin(9600); // the ble4.0 baud rate Serial.begin(9600); // the terminal baud rate } void loop() { if(Serial.available()) { mySerial.print((char)Serial.read()); } if(mySerial.available()) { Serial.print((char)mySerial.read()); } } Load this script to Arduino, and then use serial terminal to enter AT commands to configure the BLE shields
  • 22. openHAB server • Install the BLE with host role to pcDuino3B • Move the switch on the BLE shield to 3.3V as pcDuino3B is 3.3V • Jump the UART to D0 and D1 as shown in picture
  • 23. Remote Sensor Node • Install the BLE with slave role to pcDuino3B • Move the switch on the BLE shield to 5 as Arduino 5V • Jump the UART to D6 and D7 as shown in the picture • The door sensor is connected to D8 and GND. • The LED is connected to D13 and GND as shown in the picture. • Load the sensor code
  • 24. Sensor Arduino Code #include <SoftwareSerial.h> #define RxD 6 #define TxD 7 SoftwareSerial mySerial(RxD,TxD); char dat; int i,flag=1; void setup() { pinMode(RxD, INPUT); pinMode(TxD, OUTPUT); pinMode(13,OUTPUT); pinMode(8,INPUT); digitalWrite(8,HIGH); mySerial.begin(9600); // the ble4.0 baud rate Serial.begin(9600); // the terminal baud rate }
  • 25. Sensor Arduino Code void loop() { if(Serial.available()) { mySerial.print((char)Serial.read()); } if(mySerial.available()) { dat = char(mySerial.read()); Serial.print(dat); if(dat == 'S') i++; if(i%2) digitalWrite(13,LOW); else digitalWrite(13,HIGH); } if( (digitalRead(8)==1)&&(flag==1)) { flag = 0 ; mySerial.write("123rn"); Serial.write("123rn"); } if( (digitalRead(8)==0)&&(flag==0)) { flag =1 ; mySerial.write("321rn"); Serial.write("321rn"); } }
  • 26. openHAB items and bindings To add a device to OpenHAB, we need to configure four files: /configurations/openhab.cfg /configurations/items /configurations/sitemap /configurations/rules/
  • 28. /configurations/items/demo. items: Number itm_garage_dist "Garage Dist [%.1f Inch]" (ALL) {mqtt="<[mymosquitto:4032:state:default]"} Contact itm_my_gar_door "Garage Door Status [MAP(en.map):%s]" <garage> (ALL)
  • 30. /configurations/rules/: rule "Convert Door" when Item itm_garage_dist received update then if(itm_garage_dist.state < 19) { itm_my_gar_door.state = OPEN } else { itm_my_gar_door.state = CLOSED } end
  • 31. Install MQTT broker “Mosquitto” on pcDuino3/3B for OpenHAB This MQTT broker bridges the data sent from Arduino sensor in the field to the OpenHAB’s MQTT server. Arduino sensors in the field can send back data in any format to pcDuino. We can use Arduino-style programming on pcDuino to receive the data, and send the data to TCP port 10000. This MQTT broker will listen to port 10000 and converts the data to MQTT protocol. Then send that data to the MQTT server in OpenHAB.
  • 32. Install Paho MQTT $sudo apt-get update $sudo apt-get install mosquitto mosquitto- clients python-mosquitto $sudo apt-get install python-pip $sudo pip install paho-mqtt
  • 33. Sample Script (Not we will use today) import socket import sys import paho.mqtt.publish as publish publish.single("4032", "05",hostname="192.168.1.39")
  • 34. Actual MQTT agent import socket import sys import paho.mqtt.publish as publish import paho.mqtt.client as mqtt import serial with open("/sys/devices/virtual/misc/gpio/mode/gpio0",'w') as UART_RX: UART_RX.write('3') with open("/sys/devices/virtual/misc/gpio/mode/gpio1",'w') as UART_TX: UART_TX.write('3') myport=serial.Serial('/dev/ttyS1',9600,timeout=20) myport.write('test') ###
  • 35. Actual MQTT agent client_connect=0 ## def on_connect(mqttc, obj, flags, rc): print("rc: "+str(rc)) def on_message(mqttc, obj, msg): #if client_connect==1: myport.write('S') #print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload)) #connection.send(msg.topic+" "+str(msg.payload)) def on_publish(mqttc, obj, mid): print("mid: "+str(mid)) def on_subscribe(mqttc, obj, mid, granted_qos): print("Subscribed: "+str(mid)+" "+str(granted_qos)) def on_log(mqttc, obj, level, string): print(string)
  • 36. Actual MQTT agent ### The following for TCP/IP from Arduino-style part ############# # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.setsockopt( socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Bind the socket to the port server_address = ('localhost', 10000) print >>sys.stderr, 'starting up on %s port %s' % server_address sock.bind(server_address) # Listen for incoming connections sock.listen(1)
  • 37. Actual MQTT agent ################ The following for subscribing to MQTT ############## mqttc = mqtt.Client() mqttc.on_message = on_message mqttc.on_connect = on_connect mqttc.on_publish = on_publish mqttc.on_subscribe = on_subscribe mqttc.connect("localhost", 1883, 60) ### Subscribe to topic '4033', which is the ID of the relay of garage mqttc.subscribe("4033", 0) mqttc.loop_start()
  • 38. Actual MQTT agent while True: # Wait for a connection #print >>sys.stderr, 'waiting for a connection' #connection, client_address = sock.accept() #client_connect=1 try: #print >>sys.stderr, 'connection from', client_address # Receive the data in small chunks and retransmit it while True: #connection.send('Hello world') ble_data = myport.readline() if len(ble_data)>0: print(ble_data) #data = connection.recv(3) #print(data) #if len(data)==0: #connection.close() #break if "test" in ble_data : print('okay') if "321" in ble_data: print >>sys.stderr, 'publish 0' publish.single("3032", "0",hostname="localhost") if "123" in ble_data: print >>sys.stderr, 'publish 1' publish.single("3032", "1",hostname="localhost") except KeyboardInterrupt: # Clean up the connection #connection.close() sys.exit(1)
  • 39. Kick off MQTT agent  After the openHAB server starts up, run python MQTT agent by typing:  sudo python ./mqtt_pubish.py  Then we can control the LED and see the status of door sensor on the web browse r and iOS app
  • 40. Seed funding and incubator program  pcDuino works with LaunchHill to provide seed funding and incubator space in Shenzhen, China to help makers launch their own businesses.  Inquiries can be made to: harry.yu@launchhill.com.