blynk
Get pin value
รู จ ั ก Blynk RESTfull API
blynk.iot-cm.com:8080/#token#/get/V1
Write pin value via GET
128.199.204.127:8080/#token#/update/V1?value=1
Hardware network status
128.199.204.127:8080/#token#/isHardwareConnected
Application network status
128.199.204.127:8080/#token#/isAppConnected
Pin history data
128.199.204.127:8080/#token#/data/V1
Get project
128.199.204.127:8080/#token#/project
QR for project cloning
128.199.204.127:8080/#token#/qr
* ดูรายละเอียดเพิ่มเติม การใช RESTfull แบบ POST / PUT
ไดตามลิ งค ข า งลา ง
https://blynkapi.docs.apiary.io/#
https://www.instructables.com/id/Home-Automation-With-ESP8266-WiFi-Without-Using-Bl/
แนะนำสำหรับ ใครที่ต้องการใช้งาน Blynk server Local ใช้งานเอง ผมทดสอบบนระบบ Ubuntu 16.0.4 และ 17 รันบน Vmware ใช้งานได้ไม่มีปัญหา แก้ไขจากต้นฉบับ Orange pi จำ Link ไม่ได้เพราะหาข้อมูลหลายเว็บมากๆๆ กว่าจะได้ หากใครต้องการสามารถทำตามนี้ได้เลย ผมใช้ mail ของ Gmail ครับ (กำลังทดสอบระบบอยู่)
##For more videos visit https://www.youtube.com/c/SidsEClassroom
#Install Java Development Kit
1. sudo apt-get install default-jre
2. sudo apt-get install default-jdk
3. sudo apt-get install software-properties-common
4. sudo apt-add-repository ppa:webupd8team/java
5. sudo apt-get update
6. sudo apt-get install oracle-java8-installer
7. sudo apt install oracle-java8-set-default
sudo apt-get install iptables-persistent #แก้ปัญหาเปิดเว็บไม่ขึ้นเนื่องจาก iptable ไม่ save
7.1 Port forwarding for HTTP/S API
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 9443
sudo netfilter-persistent save #แก้ปัญหาเปิดเว็บไม่ขึ้น เนื่องจาก iptable ไม่ save
sudo netfilter-persistent reload #แก้ปัญหาเปิดเว็บไม่ขึ้น เนื่องจาก iptable ไม่ save
#Create a directory for the server called Blynk
8. mkdir /opt/Blynk
#Move into the working directory
9. cd Blynk
#Download the server
10. wget "https://github.com/…/rel…/download/v0.27.1/server-0.27.1.jar"
#Generate self-signed certificates
11. openssl req -x509 -nodes -days 1825 -newkey rsa:2048 -keyout server.key -out server.crt
#Convert key to pem
12. openssl pkcs8 -topk8 -inform PEM -outform PEM -in server.key -out server.pem
#Copy the contents from the site given below
https://raw.githubusercontent.com/…/resou…/server.properties
#and paste it in
13. sudo nano server.properties
## server.properties เพิ่ม ip server เข้าไปด้วยครับ
listen.address=192.169.0.222
#Change the following lines
server.ssl.cert=./server.crt
server.ssl.key=./server.pem
server.ssl.key.pass=PASSWORD_USED_IN_STEP_7
#Copy the contents from the site
https://raw.githubusercontent.com/…/resourc…/mail.properties
#and paste it in
14. sudo nano mail.properties
#Set Gmail id and password. If you are using two step verification, generate app specific password from google account.
15. cd ..
#For Autostart on reboot
16. sudo nano /etc/rc.local
# Add the following command mentioned before "exit"
java -jar /opt/blynk/server-0.27.1.jar -dataFolder /opt/blynk -serverConfig /opt/blynk/server.properties -mailConfig /opt/blynk/mail.properties
&
#Now You can start the server
17. java -jar /opt/blynk/server-0.27.1.jar -dataFolder /opt/blynk -serverConfig /opt/blynk/server.properties -mailConfig /opt/blynk/mail.properties
MIC MISSMT IoT clound server ให้ power 100,000
128.199.204.127 : 8443
port 9443
ให้ power 1,000,000
Blynk คือ Application สำเร็จรูปสำหรับงาน IOT มีความน่าสนใจคือการเขียนโปรแกรมที่ง่าย ไม่ต้องเขียน App เองสามารถใช้งานได้อย่าง Real time สามารถเชื่อมต่อ Device ต่างๆเข้ากับ Internet ได้อย่างง่ายดาย ไม่ว่าจะเป็น Arduino, Esp8266, Esp32, Nodemcu,Rasberry Pi นำมาแสดงบน Application ได้อย่างง่ายดาย แล้วที่สำคัญ Application Blynk ยังฟรี และ รองรับในระบบ IOS และ Android
โครงสร้างการเชื่อมต่อ Blynk Server
Server Settings for Blynk Application
blynk.iot-cm.com:9443
เชื่อมต่อ Blynk server จาก iOS หรือ Android app
ไปยัง App Store หรือ Google Play บน Smartphone แล้วทำการติดตั้อง Blynk app แล้วเปิด Application
สร้าง user account
คลิก Create New Account
Server Settings
เลือก CUSTOM ป้อน blynk.iot-cm.com ป้อน Port 9443 คลิก OK
ป้อน Email และตั้ง รหัสใช้งาน คลิก Sign Up หรือย้อนกลับไปหน้าแรก แล้ว Log In with Facebook
หากเปิด Server สำเร็จ ก็จะเข้าหน้าตานี้เลยครับ เป็นอันเสร็จสิ้น
การเขียน Code เพื่อเชื่อมต่อ Server Blynk
Code สำหรับ esp8266 เชื่อมต่อกับ Server Blynk
Code สำหรับ Raspberry Pi
เพิ่มใน void setup()
Blynk.begin(auth, ssid, pass, "blynk.iot-cm.com", 8080);
ตัวอย่าง
void setup()
{
// Debug console
Serial.begin(9600);
// Blynk.begin(auth, ssid, pass); //ปิดค่า default เดิม
// You can also specify server:
Blynk.begin(auth, ssid, pass, "blynk.iot-cm.com", 8080);
}
จากเดิม
blynk = Blynk(token)
เป็น
blynk = Blynk(token,server='blynk.iot-cm.com',port=8080)
หรือถ้าดาวน์โหลดไลบรารี Blynk ของทาง inex http://www.inex.co.th
cd /home/pi/Desktop
git clone https://github.com/inexglobal/PiBlynk.git
แก้ไขไฟล์ใน PiBlynk ไฟล์ __init__.py บรรทัด
def __init__(self, token, server='blynk-cloud.com', port=None, connect=True):
แก้เป็น
def __init__(self, token, server='blynk.iot-cm.com', port=8080, connect=True):
fully documented in http://docs.blynk.cc/. Refer to this for the full documentation. Documentation for the Blynk Platform itself can be found by accessing the manual if the want use on this server.
Getting Started Guide -> https://www.blynk.cc/getting-started
Documentation -> http://docs.blynk.cc/
Sketch generator -> https://examples.blynk.cc/
Server นี้ Online ตลอดครับ ค่า Uptime เกือบปีแล้วครับ ไม่เคยปิดเครื่อง ไม่เคย reboot นอกจากไฟดับนาน ๆ เปิดให้ใช้ฟรีครับ สำหรับครูและนักศึกษาอาชีวะ สำหรับการเรียน การสอนและนำไปใช้งานในโครงงานต่าง ๆ มีปัญหาใช้งานไม่ได้แจ้งกลับมานะครับ
กฤษณะ มีสุข แผนกวิชาอิเล็กทรอนิกส์ วท.เชียงใหม่
email kridsana@cmtc.ac.th
Blynk Administration : https://blynk.iot-cm.com:9443/admin