IoT Tutorial #15 [ Raspberry Pi Tutorials #3 ]
If you want to use Raspberry Pi as a Gateway in Node-Gateway IoT Architecture, It mandatory to initialise CGI server on RPi3.
In this post, I will show you the steps to initialise CGI (Common Gateway Interface) Server on your Raspberry Pi (RPi3)
Following these steps sequentially as it is and you will be able to initialise CGI server on RPi3 and test it using your browser window:
If you want to use Raspberry Pi as a Gateway in Node-Gateway IoT Architecture, It mandatory to initialise CGI server on RPi3.
In this post, I will show you the steps to initialise CGI (Common Gateway Interface) Server on your Raspberry Pi (RPi3)
Following these steps sequentially as it is and you will be able to initialise CGI server on RPi3 and test it using your browser window:
Recommended Internet of Things (IOT) Courses:
- Udemy: Complete Guide to Build IOT Things from Scratch to Market
- LinkedIn: IoT Foundations: Fundamentals
- edX: Introduction to the Internet of Things (IoT)
- edureka: IoT Certification Training on Azure
- Coursera: An Introduction to Programming the Internet of Things (IOT) Specialization
- Eduonix: Internet Of Things (IOT) Bundle
Steps:
- Create a new directory using the terminal as follows:
Open the terminal and enter following commands:
- Go to the following directory and copy the following file and paste it to /home/pi/ folder:
- Create a new file and paste given code as follow:
<Paste the given code>
Press "Ctrl+x" and then hit "enter" to save the file.
- Change the executable access of the above file as follows:
- Go to Home directory and Run the "CGIHTTPServer.py" as follows:
you will see the response on the terminal as follows:
- Open Browser on Laptop (Not RPi3) and type:
Eg. 192.168.0.34:8000
You will see the directories in the browser from your RPi3
- To run the blink.py program, Type following in browser:
Eg. 192.168.0.34:8000/cgi-bin/blink.py
your blink.py script will be executed on RPi3 and
Response will be shown in the browser as follows:
Executed the task...
- Similarly, values.py can be triggered from browser window
which collect data sent through API and log it to a TEXT file on RPi3:
Open a browser window and Type following:
Eg. 192.168.0.34:8000/cgi-bin/values.py?field1=20
This will execute the python script values.py on RPi3 and store the value "20" in text file "TextFile_Out.txt" in home directory of RPi3.
For Better understanding you can watch demonstration video given below:
Downloads:
Download link is given in the Description of the YouTube video shown below.
Demonstration:
Programs:
blink.py:
values.py:
--------------------------------------------------------------------------------
Click here to see more codes for Raspberry Pi 3 and similar Family.
Click here to see more codes for Raspberry Pi 3 and similar Family.
&
Click here to see more codes for NodeMCU ESP8266 and similar Family.
&
Click here to see more codes for Arduino Mega (ATMega 2560) and similar Family.
Click here to see more codes for NodeMCU ESP8266 and similar Family.
&
Click here to see more codes for Arduino Mega (ATMega 2560) and similar Family.
Feel free to ask doubts in the comment section. I will try my best to solve it.
If you find this helpful by any mean like, comment and share the post.
This is the simplest way to encourage me to keep doing such work.
Thanks and Regards,
-Akshay P. Daga