Saturday, 10 July 2021

Starting an MQTT Subscriber

 I have three MicroSD cards, all of which I thought I had built the same, copied a good one to the other two. But only one works. The situation is that the software includes operation as an Access point, and also an MQTT server (Mosquitto) and a subscriber python program that acts on commands received to drive the GPIO pins to steer a car. 

Card 11 I took out of a working car. 

Card 9 when i tried it would turn right only, and 

Card 10 didn't work at all. What I discovered in card 10, after I had updated and upgraded the software, is the response to the commands as shown in this picture.

[Add later] 

' sudo service subscriber status' shows that it loaded and then failed. 

'sudo service subscriber enable'  gave an error 'unrecognized service'

'sudo service subscriber start'  started the service and I was able to use it. 


But this didn't keep after a reboot. 

I discovered that I needed to use

'sudo systemctl subscriber enable' to 'fix' it so that it ran on boot. 

I am now going to go through all this on card 10 and see if this is  correct .

'sudo systemctl subscriber enable' gives: Unknown operation subscriber. 

Found these three possible references:

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

https://www.instructables.com/Raspberry-Pi-Launch-Python-script-on-startup/   -- quite old. 

https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/     

  -- I am sure that I used suggestion [d] on this before. 

pi@raspberrypi:~ $ sudo systemctl daemon-reload
pi@raspberrypi:~ $ sudo systemctl enable subscriber.service
pi@raspberrypi:~ $ sudo reboot
pi@raspberrypi:~ $ Connection to 192.168.1.9 closed by remote host.

Didn't work. 

BUT: in both card 10 and 11 there is an identical file 

/lib/systemd/system/subscriber.service

I changed the subscriber.py file in 10 because it was an old one, Maybe on the next boot it will work?

Change of direction: I made an image of card-11 and copied it to card-10 and they both work.  but not relaiably.

A lot of work on subscriber.py trying to get it to start. It usually fails on startup, but if I then start it all is OK and it stays up. 

I looked in the file for Mosquitto. service and it had a line 'on failure, restart' so I added this to the file for subscriber.py and now it stays up. 




No comments: