Introduction: LabDroid: Morse Code Encoder/Decoder
Note: This instruction can not be realized 1:1 in the newest version of LabDroid. I will update it soon.
This project will show you what you can do with LabDroid. Since a Hello World is normally made based on text, light or sound, I thought for LabDroid a Morse Code based communication would be a wonderful example.
The principle for this is relatively simple: After you have sent the text to the Android device, the text is translated into Morse Code and converted into a physical movement by the built-in vibrator. In parallel, the entire time the accelerometer will be read to finally return the recognized pattern.
The code you will see doesn't show you the best way to solve this problem. Feel free to do your own reimplementation for the encoder, decoder or front end and share your version with the community! And if you have two Android devices you could try to separate the encoder and decoder.
If you like this application idea just follow LabDroid:
- 1x Android device to run the application
- Android 8.0+
Step 1: Create the Project
Before we can start with the "coding" you need to install the application, launch it and create the project.
You can get LabDroid from the Android Play Store (Link). After you installed it just open the application and accept the requested permissions. (e.g. without location permission you cannot use the GPS Node later)
Now you should see a notification with the URL which you need to open to access the IDE. Just take your PC/MAC and open the URL with the latest version of Chrome/Chromium.
To create the project just press the add button and give it a name (e.g. HelloWorld). After you click create you should be redirected to the project editor.
Step 2: The Encoder
- to add a node just double click into the workspace
- to make a connection click on an output port, keep pressing and move to the desired input port
- some nodes have settings (e.g. Script & Vibrator), just double click into the node to open these
Okay now we can start to implement the encoder.
First of all we need the WebSocket Node which allows us to send the text to the encoder. In addition we will add a Script Node with one input and one output. This Script Node will later be used to translate the text into commands for the vibrator. The Vibrator Node ist the last one we need to add. Now connect the output of the WebSocket with the input from the Script Node and do the same for connecting the Script Node with the Vibrator Node.
Our dataflow setup is done. To do the encoding you need to place the following code into the Script Node:
Step 3: The Decoder
Our last step will be to implement the decoder which should detect the vibration and print the corresponding symbols (./-).
The decoder needs two additional nodes:
- Script Node with one input and one output
- Accelerometer Node
You just need to connect in the following order: Accelerometer Node -> Script Node
And last but not least here is the code for the Script Node:
Step 4: Say "Hello World"
Now you are ready to start the project.
For that you just need to press the play button (top left corner). You should see that on your Android device a log view appears. This will also contain the decoded Morse Code.
To do the Morse Code encoding and decoding we just need a way to send a text to the WebSocket. If you know how to do feel free to implement a simple website for that. If not just go to http://www.websocket.org/echo.html and connect to ws://AndroidIP:8081/user. After you pressed the connect button you should be able to type something in the second text field. I would suggest you to try it with SOS.
Your Android device should now start to vibrate and in the same time you should see the symbols in the log. After it finished the lo should print something like "word: ... --- ..." (in case you send SOS).