Open IOT Challenge, AttA and the SpaceCows
In the real world, a lot of connected things (like wearables) are moving. Think about this (virtual) use case:
- you are a space cowboy
- you have to manage a lot of space cows
- you have to know in real time the position of each space cow (itâs important, especially, for example, if some of them are under veterinary treatment)
To solve this kind of use case, I have created a new sensor: the BoidSensor, a sensor for work with several other sensors. I was inspired for this: https://en.wikipedia.org/wiki/Boids.
Boids is an artificial life simulation originally developed by Craig Reynolds. The aim of the simulation was to replicate the behavior of flocks of birds. Instead of controlling the interactions of an entire flock, however, the Boids simulation only specifies the behavior of each individual bird. With only a few simple rules, the program manages to generate a result that is complex and realistic enough to be used as a framework for computer graphics applications such as computer generated behavioral animation in motion picture films (source)
See it in action:
Now, let see how to play with it.
Extend the BoidSensor
You have first to extend BoidSensor
class:
- extend
BoidSensor
- add some specific properties
- override some properties (
kind
,delay
,locationName
) - override
data()
method
Thatâs all!
Now you can create several âspacecowsâ and link them to a MQTT Gateway:
You can see a complete example here: https://github.com/ant-colony/atta/blob/master/sandbox/boids_samples/spacecows.groovy.
To launch it, you have to:
- run a MQTT Broker (
./broker.sh
) created with Mosca: https://github.com/ant-colony/atta/blob/master/sandbox/boids_samples/mqtt-broker.js - run a Web application (
./webapp.sh
) thatâs using Express, MQTT.js and Socket.io (to communicate with the browser): https://github.com/ant-colony/atta/blob/master/sandbox/boids_samples/webapp.js
The Web application (with a MQTT client) subscribes to cows/+
and then receive all messages published by the gateway, remember:
- then you can run the simulation:
./spacecows.sh
(that run the groovy script)
And if you want to see the result, you just have to open http://localhost:8080/
The Web application is using Socket.io client and RaphaelJS. You can see the code here: https://github.com/ant-colony/atta/blob/master/sandbox/boids_samples/public/index.html
An other sample
In the previous sample, Iâve used only one gateway and several sensors for this gateway, but we can imagine that each spacecow is connected, then for each spacecow (sensor) we have a gateway:
In this sample, every one second, we create a gateway and a spacecow, and every one second, each gateway publish her position:
You can find the complete sample here: https://github.com/ant-colony/atta/blob/master/sandbox/boids_samples/spacecows2.groovy.
Pay attention!: the front end is different, so you have to open http://localhost:8080/index2.html
hereâs what youâll get:
Have a nice day! :) Soon, something about Node Red and AttA. Stay tuned!
Tweet