Kursus IOT ESP32 Agriculture
Part 1: What
1. What is cloud hosting?
2. What is Raspberry Pi?
3. What is ESP32?
4. What is wifi?
5. What is Modbus?
6. What is HTTP?
7. What is MQTT?
8. What is WebSocket?
Part 2: Software
1. Install Arduino IDE 2.1.0
2. Install ESP32 into Arduino IDE
Rujukan: http://shahrulnizam.com/arduino-ide-esp8266-esp32/
2.1. Buka File >> Preferences
2.2. Masukkan tambahan di Additional Board Manager URLs
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
2.3. Tekan OK
2.4. Buka Boards Manager
2.5. Cari esp32 dan install esp32 by Espressif Systems
2.6. Pilih Tools >> Board >> esp32 >> ESP32 Dev Module
Part 3: ESP32
1. Cara guna ChatGPT (1/2 jam)
ChatGPT diperkenalkan oleh syarikat OpenAI pada November 2022.
Rujukan: http://shahrulnizam.com/cara-guna-chatgpt/
2. Lesson TFT (1/2 jam)
Rujukan: http://shahrulnizam.com/esp32-lesson-ttgo-display/
2.1. Masukkan library TFT_eSPI-master-2020-02-28.zip
Pilih Sketch >> Include Library >> Add .ZIP Library…
3. Lesson Wifi (1/2 jam)
Rujukan: http://shahrulnizam.com/esp32-lesson-wifi-functions/
4. Lesson Output Relay (1/2 jam)
4.1. Install ArduinoJson by Benoit Blanchon 6.21.2
Rujukan: http://shahrulnizam.com/chatgpt-esp32-control-relay/
5. Lesson ADC, sensor soil moisture (1/2 jam)
Rujukan: http://shahrulnizam.com/esp32-lesson-adc/
6. Lesson Sensor DHT22 (1/2 jam)
Rujukan: http://shahrulnizam.com/esp32-lesson-sensor-dht/
6.1. Install library DHT sensor library by Adafruit 1.4.4
6.2. Install library Adafruit Unified Sensor by Adafruit 1.1.8
7. Lesson NTP Clock (1/2 jam)
Rujukan: http://shahrulnizam.com/esp32-lesson-ntp/
7.1. Install library NTPClient by Fabrice Weinberg 3.2.1
8. Lesson Web Server (1/2 jam)
Rujukan: http://shahrulnizam.com/esp32-lesson-web-server/
9. Lesson Modbus Soil NPK (1/2 jam)
Modbus dihasilkan oleh Modicon pada 1979.
Rujukan: http://shahrulnizam.com/esp32-lesson-modbus-soil-integrated/
Read Holding Register (0x03)
Request
Slave address 1 byte
Function code 1 byte 0x03
Starting address 2 bytes 0x0000 – 0xFFFF
Quantity of register 2 bytes 0x0000 – 0x07D0
Frame checking 2 bytes
Response
Slave address 1 byte
Function code 1 byte 0x03
Byte count 1 bytes 2xN
Coils status 2 x N bytes
Frame checking 2 bytes
N=quantity of register
10. Lesson HTTP Request (1/2 jam)
HTTP dihasilkan oleh Sir Tim Berners-Lee, saintis komputer British pada tahun 1989.
Rujukan: http://shahrulnizam.com/esp32-lesson-http-request/
11. Lesson MQTT Client (1/2 jam)
MQTT dihasilkan oleh Dr. Andy Stanford-Clark dari IBM dan Arlen Nipper dari Arcom (kini Cirrus Link Solutions)
pada tahun 1999.
Rujukan: http://shahrulnizam.com/esp32-lesson-mqtt-client/
11.1. Install library PubSubClient by Nick O'Leary 2.8.0
12. Lesson Web Socket (1/2 jam)
WebSockets dihasilkan oleh Ian Hickson of Google pada tahun 2008.
Rujukan: http://shahrulnizam.com/esp32-lesson-web-socket/
12.1. Install library WebSockets by Markus 2.4.0
Part 4: Server
Rujukan 1: http://shahrulnizam.com/server-lemp/
Rujukan 2: http://shahrulnizam.com/server-mosquitto-mqtt/
Rujukan 3: http://shahrulnizam.com/raspberry-pi-nodered/
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install nginx
$ sudo apt install php-fpm php-mysql php-zip php-gd php-xml php-xmlrpc php-curl php-intl php-mbstring php-soap
$ rm -f /etc/nginx/sites-available/default
$ rm -f /etc/nginx/sites-enabled/default
$ nano /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
Ctrl+x > y > Enter
$ sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
$ sudo nginx -t
$ sudo systemctl restart nginx
$ sudo chown -R www-data:www-data /var/www/html
$ sudo chmod -R 755 /var/www/html
$ mv /var/www/html/index.nginx-debian.html /var/www/html/index.php
$ mkdir /var/www/html/php
$ nano /var/www/html/php/index.php
<?php echo phpinfo(); ?>
Ctrl+x > y > Enter
$ sudo apt install mariadb-server
$ sudo mysql_secure_installation
$ sudo mysql -u root -p
> create database iot;
> create user 'admin'@'localhost' identified by 'p@ss1234';
> grant all privileges on iot.* to 'admin'@'localhost';
> use iot;
> create table umt(timestamp int(15),id varchar(20),temperature varchar(10),humidity varchar(10),moisture
varchar(10));
> flush privileges;
> quit
$ cd /var/www/html
$ sudo mkdir adminer
$ cd adminer
$ sudo wget http://www.adminer.org/latest-mysql-en.php
$ sudo mv latest-mysql-en.php index.php
$ cd
$ sudo apt install mosquitto mosquitto-clients
$ sudo mosquitto_passwd -c /etc/mosquitto/passwd projekiot
$ sudo nano /etc/mosquitto/conf.d/default.conf
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883
Ctrl+x > y > Enter
$ sudo systemctl restart mosquito
$ bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-
nodered)
Bagi set password admin
$ node-red admin hash-pw
$2b$08$RaVawzv3lIcUwql3UZPA1.UZ2o7bClgTcR1AOVFm9BPOV71Xsk6gi
Kemudian copy password pada bahagian adminAuth
$ sudo nano ~/.node-red/settings.js
Ctrl+x > y > Enter
$ sudo systemctl enable nodered.service
$ sudo reboot now
Part 5: NodeRED
[{"id":"305bea2cacc8acae","type":"function","z":"f220633f093e40be","name":"","func":
"var url = \"http://shahrulnizam.com/iot/umt-data.php\";\nmsg.url = url + \"?mode=\" +
JSON.stringify(msg.payload);\nreturn msg;\
n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":380,"y":880,"wires":
[["5338dcc22ef52ee6"]]},{"id":"5338dcc22ef52ee6","type":"http
request","z":"f220633f093e40be","name":"","method":"GET","ret":"txt","paytoqs":false,
"url":"","persist":false,"insecureHTTPParser":false,"authType":"","senderr":false,"header
s":[],"x":550,"y":880,"wires":[["aced39179dd4a616"]]},
{"id":"aced39179dd4a616","type":"websocket
out","z":"f220633f093e40be","name":"","server":"bad8dd43d21cb19e","client":"","x":7
20,"y":880,"wires":[]},{"id":"2a518a804b7675f9","type":"websocket
in","z":"f220633f093e40be","name":"","server":"bad8dd43d21cb19e","client":"","x":22
0,"y":940,"wires":[["fee6e9871d2e9c1c"]]},{"id":"f82bf448387f6307","type":"mqtt
in","z":"f220633f093e40be","name":"umt/in","topic":"umt/in","qos":"2","datatype":"au
to-
detect","broker":"fc9b69ada63eebbb","nl":false,"rap":true,"rh":0,"inputs":0,"x":230,"y":
880,"wires":[["305bea2cacc8acae"]]},{"id":"708428613be30f1a","type":"mqtt
out","z":"f220633f093e40be","name":"umt/id","topic":"","qos":"2","retain":"","respTopi
c":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"fc9b69ada63eebb
b","x":710,"y":940,"wires":[]},
{"id":"fee6e9871d2e9c1c","type":"function","z":"f220633f093e40be","name":"","func":"
if (msg.payload != \"\") {\n var p = JSON.parse(msg.payload);\n msg.topic = 'umt/' +
p.id;\n return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":
[],"x":460,"y":940,"wires":[["708428613be30f1a"]]},
{"id":"bad8dd43d21cb19e","type":"websocket-listener","path":"/
umt","wholemsg":"false"},{"id":"fc9b69ada63eebbb","type":"mqtt-
broker","name":"","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"
usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","
birthQos":"0","birthPayload":"","birthMsg":
{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":
{},"willTopic":"","willQos":"0","willPayload":"","willMsg":
{},"userProps":"","sessionExpiry":""}]