Skip to main content

Part 5 : 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. And because we made a clean base of code, your bike is already ready to be a connected bike.

Luos engine provides a specific app called gate. This app converts Luos services' 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 of an entire fleet of bikes.

In this last step, we will not show you how to make a mobile or computer application, but rather what you can do with the JSON API out-of-the-box using a gate app service 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 the bike

To connect the bike, we use a USB board (because we own one) but you can use a more convenient one the same way, such as a Bluetooth or WiFi board. We just have to add this USB board in the network with the gate app loaded on it, and to connect it to the computer using a USB cable. We can now use Pyluos to control the bike.

info

For more information about Pyluos, you can follow our Get-started tutorial.

info

You can use Pyluos to rename your services. It can be really useful to distinguish similar services' types with different purposes. For example, we have here two State type services, 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 services in routing tables.

Here is a basic code example to connect and list services of the bike:

from pyluos import Device

# Connect your Luos network (here using a USB container)
bike = Device('/dev/cu.usbserial-DN05NM1H')
print(bike.services)

This gives us:

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 services of the bike. Services with Unknown types are the apps we made in the previous steps. Indeed, because we created new service types for our apps, Pyluos see them as Unknown, but fortunately Unknown service 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.

tip

We added a ipython_notebook script with a Python code example into this Github tutorial project folder.

Conclusion of the bike alarm tutorial series

In this tutorial, we discovered how to create a behavior using a Luos network by creating apps from scratch. We made them flexible and ready to be compatible with any other apps in any use case. Then we see how to take control of this network and apps from a computer.

Now you have all you need to create your own project from electronics to cloud interface. What will you create with it?

The author: Nicolas Rabault

CEO at Luos
Nicolas Rabault

Former roboticist, research engineer in real-time embedded systems and founder of Pollen Robotics, Nicolas Rabault is CEO of Luos. Nicolas dedicated his life to develop tools making embedded subsets work together and simplifying reusability.