I'm using mayo_rpi_logger_2 (192.168.1.136 port 1884) as the internal MQTT broker.
It is username/password protected.
Using Memu android emulator on my Windows 10 laptop I currently display:
When I issue the following manual command on the RPi:
pi@mayo_rpi_logger_2:~ $ mosquitto_pub -d -u USERNAME -P PASSWORD -r -t sport/gaa/football/mayo -m "20190314165200;Mayo for the Sam 2019;Mayo,GAA,2019,Sam,McGuire;Latest results indicate that Mayo is favourite to win the Sam McGuire cup this year;http://discoverbundoran.com/wp-content/uploads/2014/09/sam-maguire.jpg"
Client mosqpub/11742-mayo_rpi_ sending CONNECT
Client mosqpub/11742-mayo_rpi_ received CONNACK
Client mosqpub/11742-mayo_rpi_ sending PUBLISH (d0, q0, r1, m1, 'sport/gaa/football/mayo', ... (217 bytes))
Client mosqpub/11742-mayo_rpi_ sending DISCONNECT
And clicking on the "Image" button opens the Chrome browser to display the image:
So for a demo I would like to have a web portal which would allow me to select one of several messages:
Added more users:
pi@mayo_rpi_logger_2:~ $ sudo mosquitto_passwd -c /etc/mosquitto/accesslist.txt USERNAME1
Password:
Reenter password:
pi@mayo_rpi_logger_2:~ $ cat /etc/mosquitto/accesslist.txt
USERNAME1:$6$0bI37xN+pfo0hwcU$/3yLjIJ6UKSwzTeMFdHbSoJFcVM40ZnYebCHxmo3eEIYUqJ8fTpoVD3TJ8Er3n0oZT8buaqziODjmRDBuws+rQ==
pi@mayo_rpi_logger_2:~ $ sudo mosquitto_passwd -b /etc/mosquitto/accesslist.txt USERNAME2 PASSWORD2
pi@mayo_rpi_logger_2:~ $ cat /etc/mosquitto/accesslist.txt
USERNAME1:$6$0bI37xN+pfo0hwcU$/3yLjIJ6UKSwzTeMFdHbSoJFcVM40ZnYebCHxmo3eEIYUqJ8fTpoVD3TJ8Er3n0oZT8buaqziODjmRDBuws+rQ==
USERNAME2:$6$S5GNhhsaVtc+kWRY$5EliUGn7NEP4m5eFf8P4JnIKUMWuKZBOTz2Cyn9A8fqov3PwYcTncVlOLug8fXkGQGHAxtsbCHOeVHEpRP0bdA==
That got my .py scripts to execute in Apache2 :)
Now to create a cgi-bin/MQTT_functions.py library to provide the MQTT publish function
I used this exam
ple:
https://stackoverflow.com/questions/31775450/publish-and-subscribe-with-paho-mqtt-client
and did a:
pi@mayo_rpi_logger_2:~/Mercury $ pip install paho-mqtt
Got a bit of a demo going...
Script running on:
pi@mayo_rpi_logger_2:~/Mercury $ ./random_mqtt_pub.py
Publish one of 5 random topics + messages
which MQTT Dash can see:
If i had time I'd make a connection for each topic being monitored:
topics = [ "sport/gaa/football/mayo",
"news/world/uk/brexit",
"community/clare/shannon/wetlands",
"community/clare/shannon/watch/tola",
"community/clare/shannon/watch/cronan" ]
headlines = [ "Mayo wins the Sam!",
"Tressa May resigns",
"Major funding announced",
"Break in last night",
"Suspicious van" ]
keywords = [ "Mayo,GAA",
"Brexit",
"Shannon,Wetlands",
"Guards",
"Guards" ]
details = [ "Wonderful win over Dublin 10-5 to 2-3",
"PM leaves saying country is ungrateful and her colleuges are snakes",
"Microsoft provid 2M funding for Shannon",
"Guards are asking for witnesses",
"Pate number 202 D 122345" ]
images = [ "http://sway.ie/wp-content/uploads/2015/02/sam-maguire-cup-pic.jpg",
"https://s-media-cache-ak0.pinimg.com/736x/fd/9f/0f/fd9f0f271e7449bfc01a846845adf735--theresa-may-teresa.jpg",
"http://www.galvbaydata.org/galvbaydata.org/Portals/2/images/A_Sipocz_ABNC_wet.jpg",
"https://i.ytimg.com/vi/9NIab5zKzdA/maxresdefault.jpg",
"http://www.breakingnews.ie/remote/media.central.ie/media/images/b/BandonGardaStation_large.jpg?width=600&s=bn-653620" ]
It is username/password protected.
Using Memu android emulator on my Windows 10 laptop I currently display:
When I issue the following manual command on the RPi:
pi@mayo_rpi_logger_2:~ $ mosquitto_pub -d -u USERNAME -P PASSWORD -r -t sport/gaa/football/mayo -m "20190314165200;Mayo for the Sam 2019;Mayo,GAA,2019,Sam,McGuire;Latest results indicate that Mayo is favourite to win the Sam McGuire cup this year;http://discoverbundoran.com/wp-content/uploads/2014/09/sam-maguire.jpg"
Client mosqpub/11742-mayo_rpi_ sending CONNECT
Client mosqpub/11742-mayo_rpi_ received CONNACK
Client mosqpub/11742-mayo_rpi_ sending PUBLISH (d0, q0, r1, m1, 'sport/gaa/football/mayo', ... (217 bytes))
Client mosqpub/11742-mayo_rpi_ sending DISCONNECT
And clicking on the "Image" button opens the Chrome browser to display the image:
So for a demo I would like to have a web portal which would allow me to select one of several messages:
Added more users:
pi@mayo_rpi_logger_2:~ $ sudo mosquitto_passwd -c /etc/mosquitto/accesslist.txt USERNAME1
Password:
Reenter password:
pi@mayo_rpi_logger_2:~ $ cat /etc/mosquitto/accesslist.txt
USERNAME1:$6$0bI37xN+pfo0hwcU$/3yLjIJ6UKSwzTeMFdHbSoJFcVM40ZnYebCHxmo3eEIYUqJ8fTpoVD3TJ8Er3n0oZT8buaqziODjmRDBuws+rQ==
pi@mayo_rpi_logger_2:~ $ sudo mosquitto_passwd -b /etc/mosquitto/accesslist.txt USERNAME2 PASSWORD2
pi@mayo_rpi_logger_2:~ $ cat /etc/mosquitto/accesslist.txt
USERNAME1:$6$0bI37xN+pfo0hwcU$/3yLjIJ6UKSwzTeMFdHbSoJFcVM40ZnYebCHxmo3eEIYUqJ8fTpoVD3TJ8Er3n0oZT8buaqziODjmRDBuws+rQ==
USERNAME2:$6$S5GNhhsaVtc+kWRY$5EliUGn7NEP4m5eFf8P4JnIKUMWuKZBOTz2Cyn9A8fqov3PwYcTncVlOLug8fXkGQGHAxtsbCHOeVHEpRP0bdA==
Then restarted the MQTT broker:
pi@mayo_rpi_logger_2:~ $ sudo systemctl stop mosquitto
pi@mayo_rpi_logger_2:~ $ sudo systemctl start mosquitto
So now to make web page to publish a Mayo result
First to fix the .py scripts executing:
pi@mayo_rpi_logger_2:~ $ cd /etc/apache2/mods-enabled/
pi@mayo_rpi_logger_2:/etc/apache2/mods-enabled $ sudo ln -s ../mods-available/cgi.load
pi@mayo_rpi_logger_2:/etc/apache2/mods-enabled $ sudo service apache2 reload
Great!
Also had to ensure this file was OK:
pi@mayo_rpi_logger_2:/etc/apache2/mods-enabled $ cat /etc/apache2/conf-available/serve-cgi-bin.conf
<IfModule mod_alias.c>
<IfModule mod_cgi.c>
Define ENABLE_USR_LIB_CGI_BIN
</IfModule>
<IfModule mod_cgid.c>
Define ENABLE_USR_LIB_CGI_BIN
</IfModule>
<IfDefine ENABLE_USR_LIB_CGI_BIN>
ScriptAlias /cgi-bin/ /var/www/html/cgi-bin/
<Directory "/var/www/html/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
SetHandler cgi-script
</Directory>
</IfDefine>
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
That got my .py scripts to execute in Apache2 :)
Now to create a cgi-bin/MQTT_functions.py library to provide the MQTT publish function
I used this exam
ple:
https://stackoverflow.com/questions/31775450/publish-and-subscribe-with-paho-mqtt-client
and did a:
pi@mayo_rpi_logger_2:~/Mercury $ pip install paho-mqtt
Got a bit of a demo going...
Script running on:
pi@mayo_rpi_logger_2:~/Mercury $ ./random_mqtt_pub.py
Publish one of 5 random topics + messages
which MQTT Dash can see:
If i had time I'd make a connection for each topic being monitored:
topics = [ "sport/gaa/football/mayo",
"news/world/uk/brexit",
"community/clare/shannon/wetlands",
"community/clare/shannon/watch/tola",
"community/clare/shannon/watch/cronan" ]
headlines = [ "Mayo wins the Sam!",
"Tressa May resigns",
"Major funding announced",
"Break in last night",
"Suspicious van" ]
keywords = [ "Mayo,GAA",
"Brexit",
"Shannon,Wetlands",
"Guards",
"Guards" ]
details = [ "Wonderful win over Dublin 10-5 to 2-3",
"PM leaves saying country is ungrateful and her colleuges are snakes",
"Microsoft provid 2M funding for Shannon",
"Guards are asking for witnesses",
"Pate number 202 D 122345" ]
images = [ "http://sway.ie/wp-content/uploads/2015/02/sam-maguire-cup-pic.jpg",
"https://s-media-cache-ak0.pinimg.com/736x/fd/9f/0f/fd9f0f271e7449bfc01a846845adf735--theresa-may-teresa.jpg",
"http://www.galvbaydata.org/galvbaydata.org/Portals/2/images/A_Sipocz_ABNC_wet.jpg",
"https://i.ytimg.com/vi/9NIab5zKzdA/maxresdefault.jpg",
"http://www.breakingnews.ie/remote/media.central.ie/media/images/b/BandonGardaStation_large.jpg?width=600&s=bn-653620" ]
No comments:
Post a Comment