How to turn the Orange Pi/Raspberry Pi into an IoT node

1. Introduction
- From the Orange Pi hardware specification, we can build it as a: small computer, a mini server, a gateway, a media center, ... I suggest that we should not connect it directly to sensors or control actuators that need the high accuracy (but low accuracy is fine), because the current Linux based OS in it have to run many applications and services in background/foreground, so there is a delay time when reading the sensors or controlling actuators and it make the result is not accurate. But if you still want to use Linux because of rich features, you can consider to install a Real Time Linux for it.
- In order to turn the Orange Pi into an IoT node, there are some applications and services that need to be equipped:
+ mDNS: the benefits of mDNS you can refer here: Demo 9: How to use mDNS to resolve host names to Arduino ESP32 IP addresses
+ mosquitto MQTT broker, you can refer Demo 14: How to use MQTT and Arduino ESP32 to build a simple Smart home system
+ apache2 a HTTPD - Apache2 Web Server (there are others options like nginx, nodejs)
+ PHP a scripting language for making dynamic web pages.
+ sqlite3 a small, self-contained, high-reliability database (data in stored in a local file).
2. Installation 
Note: these steps below can be applied for Raspberry Pi by replacing orangepi by raspberrypi
2.1 Install mDNS
- Step 1: from command line typing: "sudo apt-get install avahi-daemon" to installl avahi
- Step 2: edit the file "sudo nano /etc/avahi/avahi-daemon.conf"
with:
[server]
host-name=orangepi
domain-name=local

With this configuration, the host name "orangepi.local" will be used to resolve IP address.
- Step 3: restart "avahi-daemon" service by command:
"service avahi-daemon restart"
- Step 4: After finishing, you can test it by command:
"ping orangepi.local" 
Now we can change the way to ssh: "ssh root@orangepi.local"
2.2 Install mosquitto
- From command line typing:
"sudo apt-get install mosquitto mosquitto-clients"
- From another machine which installed mosquitto, open 2 Terminals and type 2 commands in each Terminal:
Terminal 1: type "mosquitto_sub -v -h orangepi.local -p 1883 -t '#'"
Terminal 2: type "mosquitto_pub -h orangepi.local -t 'room1/temp' -m 30
You will see:
Figure: Install mosquitto successfully
2.3 Install apache2
 - From command line typing:
"sudo apt-get update" 
and then 
"sudo apt-get install apache2"
- After finishing installation, from web browser type "http://orangepi.local/", you will see the page
Figure: Install apache2 successfully
 2.4 Install PHP
- From command line typing:
"apt-get install php libapache2-mod-php -y"
-  After finishing installation, from command line typing:
"sudo mkdir /var/www/html/phphello"
"sudo nano /var/www/html/phphello/hello.php"
copy and paste content: Hello World
'; ?>
then Ctrl + O and Ctrl + X
- From web browser go: "http://orangepi.local/phphello/hello.php"

Figure: Install PHP successfully

2.5 Install sqlite3
- From commad line typing:
"sudo apt-get install sqlite3 libsqlite3-dev"
- After finishing installation, from command line type: "sqlite3" and see
Figure: Install sqlite3 successfully
Done!!!

Post a Comment

0 Comments