Wednesday, 9 April 2025

2025-Car4

 from the previous version I have copied some bits off to reuse. 

Basically to do with starting the subscriber. 

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


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.


https://raspberrytips.com/access-point-setup-raspberry-pi/ 


**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.1 ??? 

** Wifi  rc-car Ashmeads  Access Point 192.168.4.1/24  GW 192.168.4.254


Some of the commands I will need after re-initialising

/home/peterm/mqtt/subscriber.py

added in sudo nano /lib/systemd/system/subscriber.service


sudo apt-get install python3-pip


sudo apt install python3-paho-mqtt


Rebooted, and systemctl status for mosquitto and Subscriber.service showed both running. 


sudo systemctl enable mosquitto   started Mosquitto. 


Tried to connect via WiFi with controller, Eventually it said "Attempting MQTT' 

but nothing happened. 


How do I tell if AP mode is done and DHCP is set? 


https://raspberrytips.com/access-point-setup-raspberry-pi/    This looks pretty good. I shall run through it as If I hadn't already tried. 


Set country GB


sudo nmcli con add con-name hotspot ifname wlan0 type wifi ssid "rc-car"


sudo nmcli con modify hotspot wifi-sec.key-mgmt wpa-psk

sudo nmcli con modify hotspot wifi-sec.psk "Ashmeads"


sudo nmcli con modify hotspot 802-11-wireless.mode ap 802-11-wireless.band bg ipv4.method shared

Looks like it is nearly there,  journalctl | grep wifi


26/6/2025  Just discovered :
https://forums.raspberrypi.com/viewtopic.php?t=289311

The answers suggested here might just work. 

Have copied the text for subscriber.service from here,


[Unit]
Description=MQTT Subscription Service
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/bin/python3 /home/pi/mqtt/subscription.py

[Install]
WantedBy=multi-user.target

----------------------------
Changed the path to suit and name to subscriber.py. 

27/6/2025
from https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/

have edited 
/lib/systemd/system/subscriber.service
/etc/mosquitto/mosquitto.conf to allow anonymous connections
and checked  /home/peterm/pi/mqtt/subscriber.py


How to do it, and check it,

https://raspberrytips.com/access-point-setup-raspberry-pi/

Found a command that shows that dhcp is not installed. 
service --status-all
[ note - Mosquitto and Subscriber were not running either]

from this site shows how to do it:
https://raspberrytips.com/dhcp-server-on-raspberry-pi/

How to install and set up dnsmasq. 
Seems to work.

no, tablet doesn't connect, but wemos does. 
not quite, no log from subscriber, or reaction on LEDs.

sudo systemctl status subscriber
 showed that it failed because it could not find the file name. I had the wrong path, so I simplified it to /home/peterm/mqtt.'files'  and then edited the subscriber.service file. 

same problem with test file path in subscriber.py

Now I have the error: 
 subscriber.service - MQTT Subscription Service
    Loaded: loaded (/lib/systemd/system/subscriber.service; enabled; preset: enabled)
    Active: failed (Result: exit-code) since Sun 2025-06-29 16:00:21 BST; 6s ago
  Duration: 2.839s
   Process: 1004 ExecStart=/usr/bin/python3 /home/peterm/mqtt/subscriber.py (code=exited, status=1/FAILURE)
  Main PID: 1004 (code=exited, status=1/FAILURE)
       CPU: 2.604s

Jun 29 16:00:20 raspberrypi python3[1004]:     import RPi.GPIO as GPIO
Jun 29 16:00:20 raspberrypi python3[1004]:   File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 927, in <module>
Jun 29 16:00:20 raspberrypi python3[1004]:     RPI_INFO = _get_rpi_info()
Jun 29 16:00:20 raspberrypi python3[1004]:                ^^^^^^^^^^^^^^^
Jun 29 16:00:20 raspberrypi python3[1004]:   File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 428, in _get_rpi_info
Jun 29 16:00:20 raspberrypi python3[1004]:     raise NotImplementedError(
Jun 29 16:00:20 raspberrypi python3[1004]: NotImplementedError: This module does not understand old-style revision codes
Jun 29 16:00:21 raspberrypi systemd[1]: subscriber.service: Main process exited, code=exited, status=1/FAILURE
Jun 29 16:00:21 raspberrypi systemd[1]: subscriber.service: Failed with result 'exit-code'.
Jun 29 16:00:21 raspberrypi systemd[1]: subscriber.service: Consumed 2.604s CPU time.
~

So I have to find out how it has changed. 

2025-07-03   A Fix? 

https://forums.raspberrypi.com/viewtopic.php?t=365849

No, it wants an environment set up.   But according to 'pip3  list' I have Rpi-lgpio version 0.6 installed. 

It needs to be hacked to set the Pi revision according to the new schema. 

I think this is how I have to do it:
https://rpi-lgpio.readthedocs.io/en/latest/differences.html

cat /proc/cpuinfo  gives
HArdware : BCM2835
Revision : 000f
Model B Rev 2

Going into Python3 and  'from RPi import GPIO'  Gives and error due to old style codes. 

14/7/25 
Found this: about using gpiozero as new module built into OS.

https://raspberrytips.com/raspberry-pi-gpio-pins/    which leads to this:

https://raspberrytips.com/gpio-zero-guide-raspberry-pi/

edited subscriber.py to remove import statement

Now have this error:

peterm@raspberrypi:~ $ sudo systemctl status subscriber
× subscriber.service - MQTT Subscription Service
    Loaded: loaded (/lib/systemd/system/subscriber.service; enabled; preset: enabled)
    Active: failed (Result: exit-code) since Wed 2025-07-16 21:12:58 BST; 3min 55s ago
  Duration: 1d 19h 12min 10.815s
  Main PID: 375 (code=exited, status=1/FAILURE)
       CPU: 2.463s

Jul 16 21:12:57 raspberrypi python3[375]:     return socket.create_connection(addr, timeout=self._>
Jul 16 21:12:57 raspberrypi python3[375]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^>
Jul 16 21:12:57 raspberrypi python3[375]:   File "/usr/lib/python3.11/socket.py", line 851, in cre>
Jul 16 21:12:57 raspberrypi python3[375]:     raise exceptions[0]
Jul 16 21:12:57 raspberrypi python3[375]:   File "/usr/lib/python3.11/socket.py", line 836, in cre>
Jul 16 21:12:57 raspberrypi python3[375]:     sock.connect(sa)
Jul 16 21:12:57 raspberrypi python3[375]: TimeoutError: timed out
Jul 16 21:12:58 raspberrypi systemd[1]: subscriber.service: Main process exited, code=exited, stat>
Jul 16 21:12:58 raspberrypi systemd[1]: subscriber.service: Failed with result 'exit-code'.
Jul 16 21:12:58 raspberrypi systemd[1]: subscriber.service: Consumed 2.463s CPU time.





















No comments: