Wifly Driver  V1.0
Arpalab.c
Go to the documentation of this file.
1 /*
2  * Arpalab.c
3  *
4  * Created on: 26/10/2015
5  * Author: Victor
6  */
7 
8 #include "LPC17xx.h"
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h>
12 #include "Type.h"
13 #include "Config.h"
14 
15 #include "WiFly.h"
16 #include "Arpalab.h"
17 #include "FreeRTOS.h"
18 #include "semphr.h"
19 
20 
21 #define GET_SEND "GET$/rest/stats?nid=%d&ip=%s&app=%s&data=%d"
22 #define GET_RECEIVE "GET$/rest/feed"
23 
24 #define IP_REMOTE 80
25 #define IP_PROTO 18
26 #define BUFSIZE (BUFSIZE_WIFLY)
27 
28 xSemaphoreHandle xMutexArpalab;
29 static char *Arpalabssid;
30 static char *ArpalabPasw;
31 static uint32_t ArpalabAuthMode;
32 char resp[BUFSIZE];
33 
34 
35 
43 uint8_t Arpalab_start(char *ssid, uint32_t AuthMode, char *passw)
44 {
45  uint8_t rtn= FALSE;
46  if( xMutexArpalab == NULL )
47  {
48  xMutexArpalab = xSemaphoreCreateMutex();
49  }
50  /*Use semaphore to start driver */
51  xSemaphoreTakeRecursive( xMutexArpalab, portMAX_DELAY );
52  {
53  Arpalabssid = ssid;
54  ArpalabAuthMode =AuthMode;
55  ArpalabPasw= passw;
56  }
57  xSemaphoreGiveRecursive( xMutexArpalab );
58 
59  return rtn;
60 }
61 
62 uint8_t Arpalab_sendValue( char *dnsAddress, uint32_t id, char *app, uint32_t value)
63 {
64  uint8_t rtn= FALSE;
65  char commRemote[128];
66  char *ip;
67 
68  xSemaphoreTakeRecursive( xMutexArpalab, portMAX_DELAY );
69  {
70  Wifly_WLANConnectPing(ArpalabAuthMode, Arpalabssid, ArpalabPasw, WLAN_PING_CHECK);
71  ip=Wifly_getIp();
72  sprintf(commRemote,GET_SEND,id, ip, app, value);
73  rtn= Wifly_HTTPSend(dnsAddress, commRemote, IP_REMOTE, IP_PROTO);
74  }
75  xSemaphoreGiveRecursive( xMutexArpalab );
76 
77  return rtn;
78 }
79 
80 int32_t Arpalab_receiveValue( char *dnsAddress)
81 {
82  int32_t value;
83  char *string;
84 
85  xSemaphoreTakeRecursive( xMutexArpalab, portMAX_DELAY );
86  {
87  Wifly_WLANConnectPing(ArpalabAuthMode, Arpalabssid, ArpalabPasw, WLAN_PING_CHECK);
88  string=strcpy(resp,Wifly_HTTPReceive(dnsAddress, GET_RECEIVE, IP_REMOTE, IP_PROTO));
89  string=strstr(string, "\r\n\r\n") + strlen("\r\n\r\n");
90  value = strtol(string , &string, 10);
91  }
92  xSemaphoreGiveRecursive( xMutexArpalab );
93 
94  return value;
95 }
96 
xSemaphoreHandle xMutexArpalab
Definition: Arpalab.c:28
char string[LOGBUFSIZE]
Definition: Log.c:25
uint8_t Wifly_WLANConnectPing(uint32_t AuthMode, char *ssid, char *passw, char *pingIP)
Definition: WiFly.c:408
int32_t Arpalab_receiveValue(char *dnsAddress)
Definition: Arpalab.c:80
#define BUFSIZE
Definition: Arpalab.c:26
#define FALSE
Definition: type.h:22
char resp[BUFSIZE]
Definition: Arpalab.c:32
#define IP_PROTO
Definition: Arpalab.c:25
uint8_t Wifly_HTTPSend(char *dnsAddress, char *getCommand, uint32_t port, uint8_t proto)
Definition: WiFly.c:912
#define NULL
Definition: type.h:18
char * Wifly_getIp()
Definition: WiFly.c:752
#define WLAN_PING_CHECK
Definition: Config.h:62
#define IP_REMOTE
Definition: Arpalab.c:24
char * Wifly_HTTPReceive(char *dnsAddress, char *getCommand, uint32_t port, uint8_t proto)
Definition: WiFly.c:891
#define GET_RECEIVE
Definition: Arpalab.c:22
uint8_t Arpalab_start(char *ssid, uint32_t AuthMode, char *passw)
Definition: Arpalab.c:43
uint8_t Arpalab_sendValue(char *dnsAddress, uint32_t id, char *app, uint32_t value)
Definition: Arpalab.c:62
#define GET_SEND
Definition: Arpalab.c:21