Software apps and online services
Say you want to build an app that you want to log the Bean's serial data to a file on your computer. Normally, you'd have to go through the process of writing software that can do that. If you use Node-RED, you can avoid having to write that software since it understands how to communicate with both your computer and Bean.
In this tutorial, you'll build a Node-RED flow that logs the Bean's serial data to a file. It formats it to a CSV and adds a timestamp. This is what the CSV output will look like:
Hi I'm a Bean! , 18:48:09 GMT-0800 (PST)
* Windows or OSX computer
Node-RED is a visual programming interface for the Internet of things. If you haven’t used Node-RED with the LightBlue Bean before, you need to set it up before following this tutorial.
This is what the Node-RED flow for the project looks like:
Bean serial: Receives serial messages from a connected LightBlue Bean and passes it on to the next node in msg.payload.
Add timestamp: Makes msg.payload to an object with two properties: serial and timestamp. Serial is the serial message from the previous node and the timestamp is the current local time.
Serial-data: Attaches the serial data to a file named “serial-data”. This file can be found on your computer in your Node-RED folder.
Copy the JSON data below to your clipboard:
ArduinoStep 2: Start Node-RED server
Open your terminal. Navigate to your Node-RED folder and type
http://localhost:1880/ in your browser. Click the menu in the top right corner and choose
import > clipboard
Double click the Bean serial node and click on the pen to edit the Bean settings. Update the name to be the name of your Bean. It is important you write the exact name as it’s the only way for Node-RED to find and connect to the correct Bean.
Upload the code below to your Bean. It will make it send a serial message every ten seconds. “\n” is used to split the input when it’s received by Node-RED’s Bean serial node.
Click deploy in the top right corner and you’re done! Check your Node-RED folder on your computer to find the file “serial-data” with the CSV output.
Having trouble with this guide? Reach out to BeanTalk to get directed feedback from our developers and community!