Difference between revisions of "IoTGateway/WiseSnail"
Fred.chang (talk | contribs) (→Configure) |
Fred.chang (talk | contribs) (→Configure) |
||
Line 24: | Line 24: | ||
<br> | <br> | ||
'''Compile'''<br> | '''Compile'''<br> | ||
− | You can perform the following steps to build this library. | + | :You can perform the following steps to build this library. |
./configure | ./configure | ||
'''Or''' | '''Or''' | ||
Line 33: | Line 33: | ||
'''Compile script'''<br> | '''Compile script'''<br> | ||
− | + | :This script combines compile steps and version control handling. | |
./snailconf.sh | ./snailconf.sh | ||
'''Or''' | '''Or''' |
Revision as of 02:54, 9 September 2016
Contents
Introduction
WiseSnail is the short name of Wise Sensor Network Abstract Interactive Layer. It is a layer to define the topology and behavior of sensor network. A complete device represented in WiseSnail includes one virtual gateway, one sensor connectivity interface and several sensor devices. WiseSnail provides a form-like array which we call it infospec array to define tha parameters of sensor device. And a form-like data array updates your real time data. So, you can easy to represent your device by creating several arrays.
Source Code
GitHub
https://github.com/ADVANTECH-Corp/WiseSnail.git
OS
- Ubuntu 14.04
- OpenWRT
Requirements
Configure
Optional
--disable-paho | Disable Paho support. |
--disable-mosquitto | Disable Mosquitto support. |
Compile
- You can perform the following steps to build this library.
./configure Or ./configure --host=<your cross compiler> --prefix=<install path> make make install
Compile script
- This script combines compile steps and version control handling.
./snailconf.sh Or ./snailconf.sh --host=<your cross compiler> --prefix=<install path>
Capability
#define MAX_DEVICES 16 //The Maximum number of sensor device
#define MAX_ITEMS 16 //The Maximum number of sensor value
#define MAX_CMDS 16 //The Maximum number of command that can be processed in one second.
Structures
Infospec
Description
The infospec structure defines your parameters in sensor device. Those parameter structures will represented in Wise-Paas like a tag. this structure includes two callback functions. You can use the callbacks to define your own get and set function. The parameter button on Wise-Paas will different by whether the set function is defined or not. If the set function is defined, the value is writable by users on Wise-Paas. |
struct WiseSnail_InfoSpec{ WiseSnail_DataType type; char *name; char *unit; union { float value; char *string; }; float min; float max; char *resourcetype; WiseSnail_SetValue setValue; WiseSnail_GetValue getValue; }; |
Example |
{ WISE_VALUE, //WiseSnail_DataType "Temperature", //name "Cel", //unit 0, //value or string -100, //min 200, //max "ucum.Cel", //resourcetype, optional NULL, //set function NULL //get function } |
Data
Description
The data structure defines your value you want to update in sensor device. the cliendId and info is for internal used and will be assigned while your callback function(like set) is called. |
struct WiseSnail_Data{ WiseSnail_DataType type; char *name; union { float value; char *string; }; char *clientId; //internal WiseSnail_InfoSpec *info; //internal } |
Example |
{ WISE_VALUE, //WiseSnail_DataType "Temperature", //name 100 //value or string } |
Callbacks
Set Callback |
typedef int (*WiseSnail_SetValue)(WiseSnail_Data *data); |
Get Callback |
typedef int (*WiseSnail_GetValue)(WiseSnail_Data *data); |
Sleep callback |
typedef void (*WiseSnail_SleepOneSecond)(void); |
Functions
Initial & Uninitial
- WiseSnail_Init
void WiseSnail_Init(char *productionName, char *wanIp, unsigned char *parentMac, WiseSnail_InfoSpec *infospec, int count); |
Parameter | Description |
---|---|
productionName | Name for device. |
wanIp | Ip address. |
parentMac | The mac address of parent device. |
infospec | Optional parameter array. |
count | The size of infospec. |
- WiseSnail_Uninit
void WiseSnail_Uninit(); |
Parameter | Description |
---|---|
None | None |
Register
- WiseSnail_RegisterInterface
- One instance only includes one interface.
void WiseSnail_RegisterInterface(char *ifMac, char *ifName, int ifNumber, WiseSnail_InfoSpec *infospec, int count); |
Parameter | Description |
---|---|
ifMac | The mac address of interface. |
ifName | The name of interface. |
ifNumber | The index number of interface. |
infospec | Interface parameter array. |
count | The size of infospec. |
- WiseSnail_RegisterSensor
- The maximum number of sensor devcie, please refer to MAX_DEVICES.
void WiseSnail_RegisterSensor(char *deviceMac, char *defaultName, WiseSnail_InfoSpec *infospec, int count); |
Parameter | Description |
---|---|
deviceMac | The mac address of sensor device. |
defaultName | The default name of sensor device. |
infospec | Sensor device parameter array. |
count | The size of infospec. |
Connect
- WiseSnail_Connect
int WiseSnail_Connect(char *server_url, int port, char *username, char *password, WiseSnail_InfoSpec *infospec, int count); |
Parameter | Description |
---|---|
server_url | The address of mqtt broker. |
port | The port of mqtt broker. |
username | The username of mqtt broker.("" for none) |
password | The password of mqtt broker.("" for none) |
infospec | Connect parameter array. |
count | The size of infospec. |
Update
- WiseSnail_Update
void WiseSnail_Update(char *deviceMac, WiseSnail_Data* data, int count); |
Parameter | Description |
---|---|
deviceMac | The mac of device which you will update. |
data | Data array. |
count | The size of data. |
Loop function
- WiseSnail_MainLoop
- This is a very important function. It includes main logic and error handling. The interval of sleepOneSec must be one second.
- You also can run an external timer, but this function must be executed per one second.
- This is a very important function. It includes main logic and error handling. The interval of sleepOneSec must be one second.
void WiseSnail_MainLoop(WiseSnail_SleepOneSecond sleepOneSec); |
Parameter | Description |
---|---|
sleepOneSec | a callback function for sleep one second. |
Demo
WiseSnail_InfoSpec interface[] = {
{
WISE_BOOL,
"/Info/reset",
"",
0,
0,
1,
"",
Reset
}
};
void SetGPIO_1(WiseSnail_Data*data) {
printf("(GPIO 1) = %d\r\n",data->value);
}
void SetGPIO_2(WiseSnail_Data*data) {
printf("(GPIO 2) = %d\r\n",data->value);
}
WiseSnail_InfoSpec infospec[] = {
{
WISE_VALUE, //type
"Temperature", //name
"Cel", //unit
0, //value[union]
-100, //min
200, //max
"ucum.Cel" //resourceType
},
{
WISE_VALUE, //type
"Humidity", //name
"%", //unit
0, //value[union]
0, //min
100, //max
"ucum.%" //resourceType
},
{
WISE_IO_BOOL,
"GPIO1",
"",
0,
0,
1,
"",
SetGPIO_1
},
{
WISE_IO_BOOL,
"GPIO2",
"",
0,
0,
1,
"",
SetGPIO_2
}
};
WiseSnail_Data data[] = {
{
WISE_VALUE, //type
"Temperature", //name
100 //value
},
{
WISE_VALUE, //type
"Humidity", //name
55 //value
}
};
void sleepOneSecond() {
sleep(1);
}
#define SERVER_ADDRESS "rmm.wise-paas.com"
int main() {
//initial
WiseSnail_Init("IotGW",NULL, NULL, NULL, 0);
WiseSnail_RegisterInterface("000E4CAB1234", "Ethernet", 0, interface, 1);
if(WiseSnail_Connect(SERVER_ADDRESS, 1883, "", "", NULL, 0) == 0) {
//
// no succesful connection to broker
//
return -1;
} else {
WiseSnail_RegisterSensor("000E4C000000", "OnBoard", infospec, sizeof(infospec)/sizeof(WiseSnail_InfoSpec));
}
int count = 0;
int second = 0;
for(;;) {
if(second == 0) {
/*HDC1050_GetSensorData(&Temperature, &Humidity);
data[0].value = Temperature;
data[1].value = Humidity;
*/
if(data[0].value < 100) {
data[0].value++;
} else {
data[0].value = 0;
}
if(data[1].value < 100) {
data[1].value++;
} else {
data[1].value = 0;
}
printf("\r\n****** \033[33mSend update.\033[0m ******\r\n");
WiseSnail_Write("000E4C000000", data, 2);
count++;
}
WiseSnail_Cmd_Handler(sleepOneSecond);
second = (second+1)%5;
}
return 0;
}