Quantcast
Channel: AirQ Networks Development Blog » arduino relay
Viewing all articles
Browse latest Browse all 9

sNET library for Arduino now on github

$
0
0

After a week of testing and tuning up, we are finally ready to push the Arduino sNET library on our github account at http://github.com/airqnetworks :-) The library repository is named snet-arduino, and it can be easily downloaded using git:

$ git clone git://github.com/airqnetworks/snet-arduino.git

Those who aren’t confident with git version system can download the library zip file using this link https://github.com/airqnetworks/snet-arduino/archive/master.zip.

Library implementation is still partial. Only AirQ 300 and 310 control boards are supported at the moment. However, the underlying structure is almost complete, so we will spend less time to support all other AirQ Networks devices. There is a lack of documentation too. We’ll add documentation to our technical wiki soon. In the github repository there is a REAME file that explains the main concepts of the library. Library is really simple to use. Let’s suppose that we want to turn-on the RELAY1 of an AirQ 310 control board with a sNET address equal to 4.0.1.2. This can be simply achieved with the following Arduino code:

/* To use sNET library we have to include sNET.h in our sketch */
#include <sNET.h>
/* sNET lib uses SoftwareSerial library. 
   Arduino IDE requires that we include the header file here */
#include <SoftwareSerial.h>

/* The following line creates a sNET object. This object will be used
   interact with other device. The integer parameter say to the library
   how many end devices we'll interface */
sNET snet(1);

void setup() {
  snet.begin();
}

void loop() {
  AIRQ310 *board;

  snet.processMessages();

  /* We ask the sNET object to give us the reference the device object
   * corresponding to 4.0.1.2 board. The method sNET::getDeviceForDeviceID()
   * will return a pointer to an AIR310 object if the object was already created, 
   * otherwise it returns 0 (NULL). The device object is created as soon as 
   * sNET library captures a message coming from that device */   
  if((board = (AIRQ310 *)snet.getDeviceForDeviceID(4,0,1,2)) != 0) {
     /* Ok, the AIRQ310 object was created and we can turn RELAY1 on */
     board->setRELAY1(ON);
     while(1); /* Job done. We stop here */
  }
}

Let’s give some explanations. At line 10 we create a new sNET object. This object is responsible to collect all messages coming from the sensor networks and captured by the AirQ ShielD. Every time we create a new sNET object we must specify how many devices the shield will interact with (in this case we assume only one AirQ 310 board). Usually, an Arduino sketch uses only one sNET object.

Next on the line 19 we ask to sNET library to process all messages coming from sensor network using sNET::processMessages() method. This a cyclical task and programmer have to call this method every time they can in order to avoid that messages are lost (for more info, see attached doc in the library). sNET library will create a device object for us when a new message coming from the AirQ 310 is detected. A device object is an abstraction that allows us to interact with a wireless device without knowing underlying details of sNET protocol. Line 26 checks if the library has created the device object for us and if so we turn ON the RELAY1.

We’ll publish further details in the next days. Stay tuned ;-)


Viewing all articles
Browse latest Browse all 9

Latest Images

Trending Articles





Latest Images