Dweet.io
Last updated
Learn how to simulate devices that send out periodic dweets.
dweet.io is an IoT platform where connected devices can send messages: according to its creators, “it’s like Twitter for social machines”. IoTIFY network simulator can easily simulate devices (or “things”) that send “dweets”; this article will guide you through the simple steps involved in setting up the simulator and will show how information extracted from these generated dweets can be visualized in a graphic dashboard. We will be simulating a car that sends periodically dweets containing information such as its current location, speed and fuel level.
The network simulator template we are going to create will contain information such as the name of the simulated thing and the contents of the dweets sent by the thing. In the template creation dialog, select HTTP(S) (the messaging protocol used by dweet.io uses HTTP as application level protocol), and give your template a unique name. Then, in the template editing screen, in the HTTP parameters section select http (TCP) as protocol and insert “dweet.io” in the host field. The path of HTTP requests for sending out dweets has the format /dweet/for/<thing-name>, where <thing-name> is an arbitrary name chosen to identify your thing. There is no need to sign up to get a name for your thing, just choose a name of your liking, but keep in mind that some other thing somewhere else may be using the same name! So it is best to choose a name unlikely to be chosen by someone else. In the HTTP method field, select POST. The following figure shows an example configuration for our dweeting car:
Finally, in the message content section specify what the simulated device is going to dweet. dweet.io supports sending data in JSON format, so our dweets will contains a JSON object with a few attributes. In our example we will be simulating a car traveling from one city to another that dweets its current location, speed and fuel level. For location and speed, we can use the drive() function, which allows specifying a start and end location and generates a corresponding driving route. For fuel level, we will assume an initial value of 100% (filled tank) which decreases by a fixed amount at each successive dweet; by using the last keyword along with minimal Javascript code we can easily specify the initial value (i.e. the value sent at the first dweet) and successive values computed as a function of previous values. The following figure shows the contents of our example template, for which we choose a route from Hamburg to Frankfurt:
freeboard is a website that allows creating graphic dashboards with simple drag and drop actions; a dashboard is populated from one or more data sources specified when the dashboard is created, and dweet.io is among the supported data sources. To begin using freeboard, sign up for a free account at freeboard.io. Then, go to https://freeboard.io/account to create a new dashboard: after choosing a name for your dashboard, click Create New and you will be taken to the editing screen:
Click Add in the datasources section, then select Dweet.io as type, give a name to the data source, and insert the name you previously chose as your thing name:
Save the data source, then start building your dashboard by adding panes and widgets; for each widget, you can access data from your data source by specifying the name of attributes in the JSON object sent in each dweet, using the notation datasources[“<data_source>”][“<attribute>”], where <data_source> is the name of your data source, and <attribute> is the name of the attribute holding the data of interest. For example, the following figure shows the configuration for a widget that takes latitude and longitude values from relevant attributes of the data source (which must correspond to the names used in the network simulator template), and draws the path of the route on Google maps:
You can then add new panes and widgets to display speed and fuel level values, using for example gauge widgets. Inside the Value field of each widget, you can insert arbitrary Javascript expressions, for example to truncate a value of a certain number of decimal digits:
Once you are happy with the contents and layout of your dashboard, you can use the network simulator template you defined in step 1 to start a simulation: give a unique name to the simulation, select 1 as number of clients, then choose a number of iterations and the gap between iterations according to how long you want your simulation to last:
As soon as the simulated device start sending messages, you will see the dashboard update in real time its contents:
You can choose to keep you dashboard public, in which case it will be accessible to anyone who has its link, or make it private: just go to https://freeboard.io/account and click Edit next to the dashboard name to edits its properties.