This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.
This JavaScript code establishes a connection between two MQTT brokers, one hosted by ThingSpeak and another by Shelly Plug S Plug S. It subscribes to specific topics on the Shelly Plug S broker to receive power and temperature data, then upon receiving both values, it publishes the data to the ThingSpeak broker for further processing.
Installation
Clone the repository or download the JavaScript file.
Ensure you have Node.js installed on your system.
Install the MQTT module using npm:
npm install mqtt
Usage
Install and run Mosquitto MQTT broker:
Download and install Mosquitto from https://mosquitto.org/download/.
Start Mosquitto using the command (run as administrator):
net start mosquitto
Configure the MQTT options for both ThingSpeak and Shelly Plug S brokers in the code.
Run the JavaScript file:
node bridge.js
How it Works
Initialization: The code first imports the MQTT module and defines MQTT options for both ThingSpeak and Shelly Plug S brokers.
Connection Setup: It establishes connections to both brokers using the specified options.
Subscription: The code subscribes to specific topics on the Shelly Plug S broker to receive power and temperature data.
Message Handling: When messages are received from the Shelly Plug S broker, it extracts the data, stores it, and publishes it to the ThingSpeak broker when both power and temperature values are received.
Error Handling: The code handles any connection errors that may occur.
Connecting Shelly Plug S to MQTT using MQTT.fx (Optional)
To connect Shelly Plug S devices to an MQTT broker using MQTT.fx (you can also use mosquitto as an alternative), follow these steps for MQTT.fx:
Install MQTT.fx: Download and install MQTT.fx on your laptop from https://www.softblade.de.
Configure MQTT Broker: Open MQTT.fx and go to the "Settings" tab. Enter your IP address as the server address (we will use your laptop's IP address as an example), select the port (1883).
Connect Device and Laptop: Ensure both your Shelly Plug S device and laptop are connected to the same network.
Access Shelly Plug S Device: Log in to the Shelly Plug S device's web interface.
Navigate to MQTT Settings: In the settings menu, find the MQTT settings section.
Configure MQTT Settings: Enter the MQTT broker's IP address and port(your_laptop's_IP:1883). You dont need to enter the username and password.
Topic Configuration: Back to MQTT.fx to define topics to subscribe to.
Save Settings: Apply the changes and save the MQTT settings on both MQTT.fx and the Shelly Plug S device.
Support
For help, please open an issue on the GitHub repository or contact oundel.store@gmail.com.
Authors and Acknowledgment
This code was written by Sami EL Yaagoubi.
License
This project is licensed under the MIT License.
Project Status
Development for this project is currently active.
Feel free to contribute to the project by opening pull requests or issues.