iankillz
Posts: 4
Joined: Wed Apr 01, 2020 10:29 am

Hc-sr04 sensor readings to website

Wed Apr 01, 2020 11:16 am

Hello im new to using raspberry pi and i am doing a smart parking project using hcsr04 ultrasonic sensors. I already have the python code working it tells if a space is available or not via sensor. How can I send the sensor readings to a webpage because the website im trying to make will supposed to tell if a sensor/spot is occupied or vaccant?

User avatar
neilgl
Posts: 2226
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Hc-sr04 sensor readings to website

Wed Apr 01, 2020 3:14 pm

Maybe run a python flask server on your pi that reads the state of the sensor (you have that already) at regular intervals and returns a web page with data showing the space is occupied or free. Use a template with templateData set accordingly.

iankillz
Posts: 4
Joined: Wed Apr 01, 2020 10:29 am

Re: Hc-sr04 sensor readings to website

Thu Apr 02, 2020 9:10 am

I have my website on a separate computer which is written in PHP and uses mysql and wampserver

User avatar
neilgl
Posts: 2226
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Hc-sr04 sensor readings to website

Thu Apr 02, 2020 11:38 am

An alternative would be to use websockets - the pi acts as a server and a page on your webserver can make a connection (with javascript) to the pi websocket server to get the data.

iankillz
Posts: 4
Joined: Wed Apr 01, 2020 10:29 am

Re: Hc-sr04 sensor readings to website

Thu Apr 02, 2020 12:34 pm

neilgl wrote:
Thu Apr 02, 2020 11:38 am
An alternative would be to use websockets - the pi acts as a server and a page on your webserver can make a connection (with javascript) to the pi websocket server to get the data.
is there any tutorial on how can I do that? sorry im new to raspberry pi

User avatar
neilgl
Posts: 2226
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Hc-sr04 sensor readings to website

Sat Apr 04, 2020 5:24 pm

Have a search around and maybe look on github for the documentation for WebSocketNode https://github.com/theturtle32/WebSocke ... 0ce2772ba7.

Return to “Python”