I have the Raspberry Pi working with Communications from MQTT-Dash on my tablet. Now I am trying to understand it better in order to get my Wemos D1 application communicating with the R-Pi.
The Raspberry Pi has my software which is a 'subscriber' and the 'broker' is Mosquitto' on the Pi, and I also have Paco-MQTT on the R-Pi. MQTT-Dash is the 'publisher'.
I am using this on the R-Pi to observe the traffic received my Mosquitto:
mosquitto_sub -h 192.168.4.1 -v -t "rc-car-pwm/#"
Subscriber configuration:
broker_address= "192.168.4.1"
port = 1883
user = "rc-car-11"
password = "carr0t"
# Create client --?? Is this the same as User?
client = mqtt.Client(client_id="rc-car-11")
# Connect to broker
client.connect(broker_address,1883,60)
# Subscriber to topic
client.subscribe("rc-car-pwm")
------------------------------------
Broker Configuration:
Can't find any except default.
------------------------------------
Publisher Configuration: (MQTT-Dash)
Name: rc-car-pwm
username = rc-car-11 + Password
Client ID: rc-car-11c
and each button press sends one of the following: forward, slow, stop,motorleft, motorright, backwards
and the message payload that the subscriber gets is b'forward' etc.
-------------------------------------
whereas the monitor command above sees:
forward,slow, etc.
-------------------------------------
The Wemos configuration is at current:
const char* ssid = "rc-car"; // Wifi SSID
const char* pswd = "Ashmeads"; // WiFi Password
const char* mqtt_server = "192.168.4.1";
const char* topic = "rc-car-11"; // this is the [root topic]
and this last I think has to change to 'rc-car-pwm' because I had to put rc-car-11 into the monitor command above to see anything.
----------------------------------------
Next step is to modify the Wemos software to send one of the words to the R-Pi and see what I get.
The lines with just 'forward' or 'stop' or 'motorleft' are from MQTT-Dash,
the others are from the Wemos App. When I remove that stuff in the Wemos app, it gives errors on compile.
The line in the Wemos app that works is
client.publish( (char*) pubTopic.c_str() , (char*) payload.c_str(), true );
where pubTopic = topic , which transmits 'rc-car-pwm' and the payload is 'forward'
Sorted, now just a simple bit of programming to push the buttons and set the desired payload. And reduce the delay.
------------------------------------
And, back to
https://madsmaddad.blogspot.com/2020/10/arduino-uno-wemos-d1-mini-wifi-and-mqtt.html
16-1-2021
https://inventwithpython.com/blog/2012/04/06/stop-using-print-for-debugging-a-5-minute-quickstart-guide-to-pythons-logging-module/
adding debug statements to try and find out what is happening, but I can't find the logfile it is supposed to create.
3/2/2021 I found two Python test programs on-line, and copied in my program, and both found the same error.
https://extendsclass.com/python.html and
https://www.onlinegdb.com/online_python_debugger
But the program still didn't run.
There was more than one error. Now running
Help in using Logging:
https://raspberrypi.stackexchange.com/questions/79421/logging-data-when-using-crontab
setting to use time, and to send data in the log message:
#logging.basicConfig(filename='temp.log', level=logging.INFO,
#format='%(asctime)s: %(message)s')
logging.info('temp: ' + str(temp) + ' ||| hum: ' + str(hum))
No comments:
Post a Comment