firstly I would like to thank Sara and Rui for the excellent tutorial book on home automation. I would certanly recommend it to any body intersted in DIY home automation Well done
I have a problem when subscrbing a temperature from DS18B20 on MQTT,nodered flow
And publishing a true and false variable to a remote esp32 board hooked to a 28BYJ-48 and ULN2003 Motor Driver using the accelstepper.h library
The error message I get suggest that the watchdog timer is triggering an error, which typically indicates that the tasks are not completing within the expected time frame. This could be caused by a conflic between the accelsteppr.h and the AsyncMqttClient.h
My Arduino IDE and ESP32 board package is the latest versions.
I have included in the goodle drive the error code, the nodered flow and the esp32 code in the followind drive
https://drive.google.com/drive/folders/1otkRm_9Kwr8cmbH7DpIFUUK5-iv0mOJs
I wonder if anybody else has had a simmilar problem
Hi.
Have you tried to compile the code but without the lines that control the motor? Add just a boolean variable to save the received message and remove the lines of code that control the motor to check if it’s related to that.
Have you tried controlling the motor without the MQTT part? Just to check if the library is actually working without any issues with the current motor setup.
Regards,
Sara
HI
Have tried both
ran the code without MQTT and worls fine and have ran it with MQTT but with no stepper anda led connected to digital pin and that worked fine
regards
Dave
P S i have also tried with esp now sending the temperature and the rernote bord recieving the temperature and the stepper works fine
Hi.
I’ve looked at the library documentation and found the issue.
Basically, the runtToPosition() function can’t be used inside event loops (like you’re using, inside the onMqttMessage() functions). – check it out here.
It mentions: “ Moves the motor (with acceleration/deceleration) to the target position and blocks until it is at position. Don’t use this in event loops, since it blocks.”
How to fix this issue? Here are two options that I think might solve the issue:
1. Take a look at the library documentation and see if there is an available method that doesn’t block the code. You can check the library class reference here: https://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html
2. Another alternative is to use global variables, whose value you change inside the onMqttMessage() function, and then, inside the loop(), you constantly check the value of that variable and then you control the motor accordingly.
I hope this helps.
Regards,
Sara
Hi
I have managed to get MQTT and Stepper.h to talk to each other using global variables as you suggested.
this allows me to turn the stepper cw and ccw but i have a problem . the code turns a radiator spindlle cw to close and ccw to open and therefore must only turn once cw and not turn again untill ccw varable is recieved and then just turn once etc
i have included the code in google drive as above file nameMQTT_stepper.docs
the code at the moment works perfectly for the first 2 cycles i.e cw rotate then no movement untill ccw rotation and then no movement untill next cw . unfortunatly at thhis second cw rotaion the motor will not revolve because the cwMove varable is still true. It wouls be great if you point me in the right direction to solve this
Thanks for your help
regards Dave
Hi.
It seems that you need to add another global variable to check whether the motor has already spinned, and change it when the ccw variable is received again, but it depends on the way your code is organized.
I didn’t get any link to google docs. Can you share it again?
Regards,
Sara
Hi
you are right and I have finally got it right Thanks for your help
regards Dave
PS consider the problem solved