Intro: The purpose of this tutorial
Step 1: Make a basic alarm
Step 2: Make our alarm adaptable and hot-pluggable
Step 3: Add another app controlling the alarm
Step 4: Make our alarm evolve using a truck horn and more
Step 5: Connect our system to the cloud
Connect our system to the cloud
This entire system is a lot more than a simple alarm and it could be used as a base to make a free-floating bike system, or a connected bike.
If you followed this tutorial from the start, you should know how to make one, the only step missing being the cloud connectivity part.
Because we made a clean base of code, your bike is already ready to be a connected bike.
Luos provides a specific app called Gate. This app converts Luos modules’ messages into a JSON stream. You can output and input this JSON stream using the medium you want (USB, Bluetooth, 4G, WiFi, …).
You can directly use this JSON stream with your favorite language on a server or a computer and take control of your entire bike or a fleet of several bikes.
NOTE : more information about JSON and gate app is available in our documentation.
In this last step I won’t show you how to make a mobile or computer application, but I will show you what you can do with the JSON API out-of-the-box using a Gate app module and Pyluos (our standard Python library). After this last step, you should be ready to make your connected product by doing your software or UI as you want.
How to connect my bike
To connect my bike, I will use a USB board (because I have one) but you can use a more convenient one the same way, such as the Bluetooth or WiFi board we designed.
I just have to add this USB board in my network with the Gate app loaded on it and to connect it to my computer using a USB cable. Now I can use Pyluos to control my bike.
NOTE : for more information about Pyluos, you should read our guide to Pyluos page.
INFO : You can use Pyluos to rename your modules. It can be really useful to distinguish similar module types with different purposes. for example, here we have two
Statemodule types, but one is a button (“lock”) and the other one is a power switch (“horn”). In our case it is mandatory because apps use aliases to find modules on routing tables.
Here is a basic code example to connect and list modules of my bike:
from pyluos import Device # Connect your Luos network (here using a USB module) bike = Device('/dev/cu.usbserial-DN05NM1H') print(bike.modules)
Connected to "/dev/cu.usbserial-DN05NM1H". Sending detection signal. Waiting for route table... Device setup. ------------------------------------------------- Type Alias ID ------------------------------------------------- Gate gate 1 State horn 2 Color alarm 3 Unknown alarm_control 4 Imu gps 5 State lock 6 Unknown start_control 7
As you can see here, I have listed the modules of my bike. Modules with
Unknown types are the apps we made in the previous steps. Indeed, because we create new module type for our apps, Pyluos see them as
Unknown, but don’t worry: unknown module types still have access to standard Luos message types.
By using these standard messages, we can take control of everything:
# fake a button push to unlock the bike bike.start_control.state = False # force alarm to start (play) but start_control app still has control. bike.alarm_control.play() # force alarm to stop but start_control app still has control. bike.alarm_control.stop() # Force LED color bike.alarm.color = [30, 30, 30] # fake a button push to lock the bike bike.start_control.state = True
Using this JSON stream, you are now able to check on your bike anywhere.
I added a ipython_notebook script with a Python code example into this Github tutorial project folder.
Conclusion of this entire tutorial
In this tutorial we discover how to create a beahavior using a luos network by creating apps from scratch. We make them flexible and ready to be compatible with any other apps in any use case. Then we see how to cake control of this network and apps from a computer.
Now you have all you need to create your how project from electronics to cloud interface.
What will you make with it? let me know by commenting this post !
If you have any question or comment about this step of the tutorial, feel free to reply to this post.