-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsw_test.c
60 lines (52 loc) · 1.55 KB
/
sw_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "sw_lib/sw_bridge.h"
#include <unistd.h>
#define STATIC 10
// create the client object
static MQTTClient client;
// signal handler
void InvalidTermination(int);
int main(int argc, char const *argv[])
{
// registering signal and its handlers
signal(SIGINT, InvalidTermination); // ctrl+c
signal(SIGTSTP, InvalidTermination); // ctrl+z
// Information
short iRet_Connect = 0, s_index = 0, iRet_RegisDev = 0;
char address[] = "127.0.0.1:1883";
char clientID[] = "Axonet-Emsys";
char HardWareID[] = "IoT-Linux_Gateway";
char specification[] = "7dfd6d63-5e8d-4380-be04-fc5c73801dfb";
char Data[] = "Temperature";
float value = 32.865;
float latitude = 2.154;
float longitude = 5.161;
float elevation = 520;
char alertType[] = "INFO";
char alertMessage[] = "SW_Linux";
// connect to the sitewhere network
if((iRet_Connect = ConnectDevice(&client,address,HardWareID,clientID)) == STATUS_SUCCESS)
{
// register our device
if((iRet_RegisDev = RegisterDevice(client,HardWareID,specification)) == STATUS_SUCCESS)
{
for(s_index = 0; s_index < STATIC; s_index++)
{
// send messages to sitewhere
SendMeasurement(client,HardWareID, Data, value);
SendLocation(client,HardWareID,latitude,longitude,elevation);
SendAlert(client,HardWareID,alertType,alertMessage);
sleep(10);
}
}
}
// disconnect the connection
DisconnectDevice(client);
return 0;
}
// signal handler
void InvalidTermination(int signum)
{
// disconnect the connection
DisconnectDevice(client);
exit(0);
}