Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mqtt_client_test #498

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open

mqtt_client_test #498

wants to merge 11 commits into from

Conversation

ellebi2000
Copy link

@ellebi2000 ellebi2000 commented May 25, 2024

This PR introduces functionality for temperature monitoring and LED control on a Raspberry Pi Pico W using MQTT. The key features include:

Temperature Monitoring:

Reads onboard temperature using the ADC.
Converts ADC readings to Celsius or Fahrenheit.
Publishes temperature to the /temperature MQTT topic every 5 seconds.

LED Control:

Controls the onboard LED via MQTT messages received on the /led topic.
Turns the LED on/off based on "On" or "Off" messages.
Publishes LED state to the /state MQTT topic.

WiFi and MQTT Configuration:

Connects to WiFi using predefined SSID and password.
Connects to the MQTT broker with the given IP address and port.
Configures an MQTT client with a predefined client ID and keep-alive period.

MQTT Callbacks:

mqtt_incoming_data_cb: Handles incoming data and controls the LED.
mqtt_incoming_publish_cb: Handles incoming publish events.
mqtt_connection_cb: Manages MQTT connection status and subscribes to the /led topic.

@martincarapia
Copy link

Everything checks out. I just tested it and the code runs great!
image
Just those little nitpicks and it's good to be approved!

@francdoc
Copy link
Contributor

francdoc commented Jun 1, 2024

This implementation is working great. I tested your publisher sample with a subscriber from this repository (running on a Linux machine) simple_subscriber.c.

I configured your code to publish to the address "35.156.49.117" (broker.hivemq.com) on port 1883, and the MQTT-C subscriber successfully listened to the transmitted temperature data.

Thank you, ellebi2000.

@ellebi2000
Copy link
Author

I have removed the comment in Italian and others that are not strictly necessary.
I'm very happy that your implementations are working as expected @martincarapia @francdoc

@lurch
Copy link
Contributor

lurch commented Jul 5, 2024

Perhaps this should be in pico_w/wifi/mqtt instead of pico_w/mqtt ?

EDIT: Also, do you really need separate mqtt and mqtt/mqtt_client directories? 🤔 Perhaps it could be "collapsed" to just a single pico_w/wifi/mqtt_client directory?

@peterharperuk
Copy link
Contributor

@ellebi2000 If you can confirm that we're ok to release this with the same license as everything else (BSD-3-Clause license), I'll address the review comments and get this merged. Thanks.

@ellebi2000
Copy link
Author

@ellebi2000 If you can confirm that we're ok to release this with the same license as everything else (BSD-3-Clause license), I'll address the review comments and get this merged. Thanks.

Yes, I confirm that this code can be released under the BSD-3-Clause license.
Thank you for reviewing and helping with the process! 😊 @peterharperuk

@peterharperuk peterharperuk self-assigned this Jan 28, 2025
ellebi2000 and others added 10 commits January 29, 2025 14:57
Fix review comments and build warnings.
Use MQTT_SERVER build variable instead of hard coding IP address.
Make a DNS request for the server.
Use async timer for publishing the temperature.
Move the code down one level
print, just print the message to stdout
ping, publish uptime to pong
exit, quit the client
Add some defines for some magic numbers
Disabled by default with MQTT_UNIQUE_TOPIC
@peterharperuk
Copy link
Contributor

I rebased the PR

peterharperuk
peterharperuk previously approved these changes Jan 30, 2025
@ellebi2000
Copy link
Author

I rebased the PR

@peterharperuk Amazing !

@peterharperuk peterharperuk added this to the 2.1.1 milestone Feb 5, 2025
Change /pong to /uptime
Display a message if MQTT_SERVER is not defined
Put picow_ in the name like the other examples
Add details to the readme!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants