Read and Write to Devices With Converse.js

This tutorial is regarding using Converse.Js to read values and write values to devices, and also retrieve history of fields.

Getting Started

Follow the instructions given here

Use this converse.js file instead of the one given in above link.

Start with logging into an XMPP account

  • Log into your xmpp account.

  • Contacts will be displayed with an Icon to their left.

  • These icons determine the type of contacts (Sensor Devices, Control Devices or Contacts)

  • Open a Chatbox with a Device.

  • We have used Command Feature to implement the functions.

Reading Values from a Device

  • It works for Sensor as well as Control Devices.

  • The command for reading a value is ‘/read’.

  • It will display the fields stored in the device along with their present values. Like this :

Read Requests

Writing Value to a Field

  • It works for Control Devices.

  • First perform a Read to know the FieldNames.

  • The command for writing a Value to a FieldName is ‘/write FieldName Value’.

  • Now you can again perform a Read to check if the Value for that FieldName is changed. Like this :

Write Requests Step-1 Write Requests Step-2 Write Requests Step-3

History Retrieval for a Field

  • It works for Sensor as well as Control Devices for Fields that store their History.

  • The command to retrieve Hisotry of a FieldName is ‘/history day/week/month/year FieldName’.

  • Output for the same looks like this:

History Requests Step-1 History Requests Step-2 History Requests Step-3

Hope you like playing around with it :)

Adhish Singla

Written by