Answered step by step
Verified Expert Solution
Question
1 Approved Answer
the Arduino part will be reading RGB signals from python as we set the value for a particular color through mqtt. and then send to
the Arduino part will be reading RGB signals from python as we set the value for a particular color through mqtt. and then send to m5stick c plus.
The goal of this lab is to design a smart "lightbulb". The lightbulb will turn on and off with a button. A remote user can also see if the lightbulb is on or off, and can remotely toggle it as needed. They can also change the light color. Note, below you should (probably) have 3 MQTT topics: - light_status - published by the arduino, with 4 values indicating on/off, and R,G,B color - light_control_status - published by the controller, with 1 value indicating on/off - light_control_color-published by the controller, with 3 values indicating color The above are best written to send binary encoded messages as these are much easier and more. efficient to work with in microcontrollers than strings that have to be parsed. The Arduino Program (M5StickCPlus) (Name your program lab3_light) The LCD will be used as the "lightbulb". Here is a general idea of what the sketch should look like, though your implementation may differ considerably and still be correct. You can use the test.mosquitto.com broker, OR, you can use the broker at info8000.ga. The broker username is giiuser and the password is giipassword - In setup you connect to WiFi and the MQTT broker you also setup a callback for messages, and subscribe to the light_control_status and light_control_color topics (use your ugaid to differentiate from others, e.g. elee2045sp23/kjohnsen/light_control_color) - In loop Poll MQTT for messages repeatedly check for button presses, if the button is pressed, you should toggle the LCD backlight on and off. Use the MS.Axp.screenBreath() function to do this ( 0 will turn]it off, 15 will be fully on). Every 2 seconds, publish a message to the light_status topic indicating the status and color of the lightbulb. - In the MQTT message callback If the message is light_control_status, then change the status If the message is light_control_color, then change the color After setting these, immediately publish the status and color back to light_status, so the result of the command is instantly realized - Some helpful functions from the solution (note, status is an integer, 0 or 1,r,g& are integers that are between 0 and 255 ): //stolen from https://forums, adafruit. com/viewtopic.php?t=21536 uint16_t rgb565(uint8_t r, uint8_t g, uint8 t b) \{ return ((r/8)11)((8/4)5)(b/8); \} here we can use WiFi, mqtt (as provided in the page) , esp_wpa2 , eduroam etc.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started