About dweet.io

Dweet.io is a nice service that allows devices to communicate through messages sent using simple HTTP requests. Dweet.io also allows for the creation of alerts, based on simple JavaScript expressions that are evaluated against the content of the messages that are sent/received.

Using dweet.io from scriptr.io

Dweet.io’s simplicity makes it a good tool to implement simple IoT applications and to easily establish communication among HTTP-enabled devices and services. However, as soon as your requirements evolve with the addition of more complicated features, such as transforming your data and/or persisting it or orchestrating the execution of services and devices, it becomes necessary to resort to a more advanced platform such as scriptr.io, which can be used to extend the capabilities of the applications built using dweet.io. In order to facilitate the combination of dweet.io with scriptr.io, we provide a simple connector that can be imported into the scriptr.io workspace and used from within scripts.

Sample application

We’ll illustrate how to use the dweet.io connector with a simple application: let’s assume we have a simple device, composed of a pressure sensor and some HTTP-enabled micro-controller. The device is monitoring the main entrance door lock: when a pressure is detected on the lock, the device posts the corresponding measure to a decision table created on scriptr.io, which determines if this matches an intrusion attempt or not. When it does, it posts a message via dweet.io, which will be consumed by other locks that are listening to messages published by the main entrance door.

dweeeting

To keep things simple in our example, we’ll consider the following: if pressure is > 150, then it is an intrusion attempt. If pressure is > 80 and 3 or more pressure events have been detected within 5 seconds, then it is also an intrusion attempt.

decision-table

Using the connector

From your scriptr.io workspace , click on the arrow next to “+New Script” then click on “Import Module”. Browse through the list of available modules and install dweet.io.

First, require the dweet.io module from within the decistion table script:

var dweet = require("dweet"); // make sure to specify the correct path 

Then create an instance of the Dweet class, passing the name of the device on behalf of which you will be posting messages:

var dweeter =new dweet.Dweet("main_entrance_door");

Post a message:

var message = {"msg":"intrusion"};
dweeter.postDweet(message);

Add dweet behavior to the decision table

Let’s adapt the above to our scenario by incorporating it to the Post-script section of the decision table:
post-script

Try it

Clicking on the below links invokes the decision table and opens the result of the request in a separate tab of your browser. You can change the value of the pressure parameter in the URL to try different configuration.
Send pressure

Get the source code

Source code on Github