Turn the Rapiro into an IoT device with Eclipse Orion and MQTT
thingiverse
The provided code is a Node.js application that bridges MQTT messages with serial port commands for controlling an Arduino-based robot called Rapiro. The app listens for incoming MQTT messages, interprets them as commands, and sends the corresponding commands to the Arduino via the serial port. Here's a step-by-step explanation of how it works: 1. **MQTT Setup:** Lines 22-25 configure the MQTT client to connect to the iot.eclipse.org broker and subscribe to the topic `benjamin/rapiro/command`. 2. **Serial Port Setup:** The code sets up the serialport module on lines 14-19, specifying the name of the serial port (`/dev/ttyACM0`), its baudrate (`9600`), parity checking settings, and other low-level parameters. 3. **MQTT Message Callback:** When a new MQTT message is received (line 40), the code checks if the payload contains the string `"TAKE_PICTURE"`. If it does, the app uses `raspistill` to take a picture and outputs the binary JPEG encoded in base64 on stdout. 4. **Publishing Pictures:** The `publishPicture` callback takes this output and publishes it as an MQTT message (lines 31-35) with a topic of `benjamin/rapiro/pic`. 5. **Serial Commands:** If the payload is not `"TAKE_PICTURE"`, the code uses the serialport module to write the received command on the serial port, assuming it's a valid serial command that Rapiro can understand. 6. **Web UI Setup:** The web UI is built using Eclipse Paho's JavaScript client for MQTT over WebSockets. When a button is clicked, an MQTT message is published on the topic `benjamin/rapiro/command` with a payload indicating the action to be performed by Rapiro (e.g., "STOP!"). 7. **Web UI Callbacks:** The web UI uses three callbacks: `onConnect`, `onConnectionLost`, and `onMessageArrived`. When connected, it subscribes to the topic `benjamin/rapiro/pic` and sends a message. On disconnection or error, it logs messages for debugging purposes. When an image is received (base64 encoded in the payload), it updates the image source of an HTML element with that base64 string. 8. **Testing:** The user can test this setup using the Orion shell to launch the Node.js app on the Raspberry Pi and use the web UI to control Rapiro remotely via MQTT messages.
With this file you will be able to print Turn the Rapiro into an IoT device with Eclipse Orion and MQTT with your 3D printer. Click on the button and save the file on your computer to work, edit or customize your design. You can also find more 3D designs for printers on Turn the Rapiro into an IoT device with Eclipse Orion and MQTT.