Tuesday, 21 May 2024

Lets get car-4 working again ( May 2024) - Still trying November

December 10, 2024: 

Here are two good pages about setting up MQTT and getting Publisher/broker and subscriber working. 

https://bytebeam.io/blog/getting-started-with-mqtt-on-raspberry-pi-using-python/ - Probably better

 as my Subscriber is written in Python. July 2023 Everything except how to set it up to start at boot.


https://diyi0t.com/microcontroller-to-raspberry-pi-wifi-mqtt-communication/  

*** Excellent step-by-step setting up publisher, Broker and subscriber, except for autostart subscriber.

Now I need to find out how to get a  python Subscriber to start at boot.  

This link gives me the best help on what I want to do. 

https://www.codementor.io/@ufuksfk/how-to-run-a-python-script-in-linux-with-systemd-1nh2x3hi0e

------------------------------------------------

Subscriber service now starts, but path to file is now

/home/peterm/pi/mqtt.  The peterm is added because the Pi now needs a user and that is peterm. 


14/12/24 Trying to get AP configured, but failing

https://themakermedic.com/posts/Pi-AP-Mode/ after configuring, tablet cannot find the SSID. 

Will look at this one tomorrow:

https://www.raspberryconnect.com/projects/65-raspberrypi-hotspot-accesspoints/168-raspberry-pi-hotspot-access-point-dhcpcd-method


------------------------------------------------


Alternatively using crontab:

https://tutorials-raspberrypi.com/control-raspberry-pi-robots-via-infrared-remote-control-part-3/

------------------------------------------------------------------------------------

Here is the earlier post about it.

https://www.blogger.com/blog/post/edit/preview/5415560036905179298/8810457589872963960


GPIO PIN            Wire colour 

                                  Car                             Test Rig

6                            White                            Pale yellow

12                          Orange                          White

18                         Red                                Blue

19                        Yellow                            Orange

23                        Green                             Yellow

Now I can swap R-Pis and see if there is a problem with the car one. 

swapped boards, and test rig ran the same, except that after analog left, left LED kept flickering and I couldn't stop it. Another software fault.

Also Red forward LED on at startup. 

----------------------

23/8/2024 

HAve rebuilt software using latest RaspIOS and it is different. 

Looking at this to try and figure out how to configure it.

https://bytebeam.io/blog/getting-started-with-mqtt-on-raspberry-pi-using-python/

Problem installing Paho-mqtt. Need to look into it. 

12/10/24 working through this. Got through the update of Setting up Python dependencies and installing MQTT Python Libraries  

NOW! I remember, On boot I have to start the subscriber program.  I'll look in a previous writeup and see if I described the process. 


This goes quickly but gives instructions on how to enable the subscriber. and set the broker to run in the background. 

https://www.youtube.com/watch?v=za-IIZ1xVbA



22/10/24  https://forums.raspberrypi.com/viewtopic.php?t=318784  this gives some good advice for simplifying subscriber.

23/11/24 Useful commands  https://linuxhandbook.com/systemctl-commands/

https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/

https://randomnerdtutorials.com/testing-mosquitto-broker-and-client-on-raspbbery-pi/

https://pimylifeup.com/raspberry-pi-mosquitto-mqtt-server/

https://tutorials-raspberrypi.com/raspberry-pi-mqtt-broker-client-wireless-communication/?utm_content=cmp-true            [ this one needs some editing and explanations.]

 What I am missing is "sudo python mqtt_subscriber.py"  and what I need is to know how to enable this in startup. 

Useful from Pimylifeup:  sudo systemctl status mosquitto

Starting subscriber at login:

https://linustechtips.com/topic/1465144-run-python-scripts-on-startup/

Few ways,

 

Create a bat file and put it in the startup folder.  The bat file would look something similar to this

python3 [path to run]

Or however you run a python script on your computer in command prompt.  Confirm that it runs your python script and then put in your startup folder and it will run at login.

 

Other options, go to task scheduler.

Create a new task

Add a new trigger; selecting on startup (I can't remember you might need to click the run even if user isn't logged in...can't remember exactly when that triggers).  You could also do on login


EVEN Better:

https://www.howtogeek.com/687970/how-to-run-a-linux-program-at-startup-with-systemd/


=======================================================================

starting from scratch.


2025-1-4 image imaged onto 16Gb card. Set the userID and wifi parameters.

Fing shows RPi at 192.168.1.26

Had to change keygen, but then able to login via ssh.

sudo raspi-config to expand filessystem, and reboot.


sudo apt update, 

sudo apt-get install firmware-zd1211.

and nmtui to configure Ethernet IP and Wifi 

Ethernet   192.168.1.9/ 24    GW=192.168.1.31

Wifi  rc-car Ashmeads  Access Point 192.168.4.1/32  GW 192.168.4.255


 sudo reboot  

on ip .9 - good

check ifconfig

OK. 


Now see above to set up MQTT


https://diyi0t.com/microcontroller-to-raspberry-pi-wifi-mqtt-communication/ 

See Broker setup

Installation doesn't like reference to Raspian. 

Looks like it needs a DNA specified in IP config.   Back to nmtui.  No effect.

Found 

https://stevessmarthomeguide.com/install-mosquitto-raspberry-pi/


Which includes some setup that the others haven't even if it has not been updated for Raspbios 'Bookworm'.


But problem here too:

Resolving repo.mosquitto.org (repo.mosquitto.org)... failed: Temporary failure in name resolution.
wget: unable to resolve host address ‘repo.mosquitto.org’

None of the solutions seem to work because 

sudo systemctl status systemd-resolved.service  could not be found. 


More work needed here: Tomorrow.