Commit f98a930cce7059a29bf50a08548d4b61ec6b8bd1

Authored by Imanol-Mikel Barba Sabariego
1 parent e7312508

--no commit message

Project/applications/smartcities/buglist.txt
1 -- NTP sudden reset  
2 - Investigate leaks 1 - Investigate leaks
  2 +- Pressure sensor memory
3 - Test sound sensor 3 - Test sound sensor
4 -- Test multiple sensors  
5 \ No newline at end of file 4 \ No newline at end of file
  5 +- Test multiple sensors with DB9
6 \ No newline at end of file 6 \ No newline at end of file
Project/applications/smartcities/callbacks.c
@@ -7,7 +7,7 @@ void dhcp_connect_result_cb(int result) @@ -7,7 +7,7 @@ void dhcp_connect_result_cb(int result)
7 { 7 {
8 libwismart_GetCurrentIP(&ip,NULL,NULL); 8 libwismart_GetCurrentIP(&ip,NULL,NULL);
9 DBG_CALLBACKS("IP: %d.%d.%d.%d \r\n",ip.addr[3],ip.addr[2],ip.addr[1],ip.addr[0]); 9 DBG_CALLBACKS("IP: %d.%d.%d.%d \r\n",ip.addr[3],ip.addr[2],ip.addr[1],ip.addr[0]);
10 - connected = 1; 10 + connected |= CONNECTED_NOW;
11 retries = 0; 11 retries = 0;
12 } 12 }
13 else if(result==LIBWISMART_DHCP_TIMEOUT) 13 else if(result==LIBWISMART_DHCP_TIMEOUT)
Project/applications/smartcities/flash.sh
@@ -2,4 +2,4 @@ @@ -2,4 +2,4 @@
2 2
3 make clean 3 make clean
4 make all 4 make all
5 -st-flash write build/smartcities.bin 0x8000000 5 +st-flash --reset write build/smartcities.bin 0x8000000
Project/applications/smartcities/i2c.c
@@ -51,7 +51,6 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) @@ -51,7 +51,6 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
51 { 51 {
52 // wait for I2Cx EV6, check if Slave has acknowledged Master transmitter mode 52 // wait for I2Cx EV6, check if Slave has acknowledged Master transmitter mode
53 } 53 }
54 - DBG_I2C("Slave -> Master ACK\r\n");  
55 } 54 }
56 else if(direction == I2C_Direction_Receiver) 55 else if(direction == I2C_Direction_Receiver)
57 { 56 {
@@ -59,8 +58,8 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) @@ -59,8 +58,8 @@ void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
59 { 58 {
60 // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode 59 // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode
61 } 60 }
62 - DBG_I2C("Slave -> Master ACK\r\n");  
63 } 61 }
  62 + DBG_I2C("Slave -> Master ACK\r\n");
64 } 63 }
65 64
66 void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) 65 void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
@@ -81,7 +80,6 @@ void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) @@ -81,7 +80,6 @@ void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
81 { 80 {
82 // wait for I2Cx EV6, check if Slave has acknowledged Master transmitter mode 81 // wait for I2Cx EV6, check if Slave has acknowledged Master transmitter mode
83 } 82 }
84 - DBG_I2C("Slave -> Master ACK\r\n");  
85 } 83 }
86 else if(direction == I2C_Direction_Receiver) 84 else if(direction == I2C_Direction_Receiver)
87 { 85 {
@@ -89,8 +87,8 @@ void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction) @@ -89,8 +87,8 @@ void I2C_restart(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction)
89 { 87 {
90 // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode 88 // wait for I2Cx EV6, check if Slave has acknowledged Master receiver mode
91 } 89 }
92 - DBG_I2C("Slave -> Master ACK\r\n");  
93 } 90 }
  91 + DBG_I2C("Slave -> Master ACK\r\n");
94 } 92 }
95 93
96 void I2C_write(I2C_TypeDef* I2Cx, uint8_t data) 94 void I2C_write(I2C_TypeDef* I2Cx, uint8_t data)
@@ -121,7 +119,6 @@ uint8_t I2C_read_nack(I2C_TypeDef* I2Cx) @@ -121,7 +119,6 @@ uint8_t I2C_read_nack(I2C_TypeDef* I2Cx)
121 { 119 {
122 DBG_I2C("Listening for byte in I2C (NACK)\r\n"); 120 DBG_I2C("Listening for byte in I2C (NACK)\r\n");
123 I2C_AcknowledgeConfig(I2Cx, DISABLE); 121 I2C_AcknowledgeConfig(I2Cx, DISABLE);
124 - //I2C_GenerateSTOP(I2Cx, ENABLE);  
125 while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) 122 while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED))
126 { 123 {
127 // wait until one byte has been received 124 // wait until one byte has been received
@@ -135,10 +132,6 @@ void I2C_stop(I2C_TypeDef* I2Cx) @@ -135,10 +132,6 @@ void I2C_stop(I2C_TypeDef* I2Cx)
135 { 132 {
136 DBG_I2C("Sending I2C Stop...\r\n"); 133 DBG_I2C("Sending I2C Stop...\r\n");
137 I2C_GenerateSTOP(I2Cx, ENABLE); 134 I2C_GenerateSTOP(I2Cx, ENABLE);
138 - /*while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTING))  
139 - {  
140 - // wait for I2C1 EV8_2 --> byte has been transmitted  
141 - }*/  
142 DBG_I2C("Stop sent\r\n"); 135 DBG_I2C("Stop sent\r\n");
143 } 136 }
144 137
Project/applications/smartcities/include/callbacks.h
@@ -9,6 +9,9 @@ @@ -9,6 +9,9 @@
9 #define WIFI_MODE_SOFTAP 2 9 #define WIFI_MODE_SOFTAP 2
10 #define MAX_RETRIES 5 10 #define MAX_RETRIES 5
11 11
  12 +#define CONNECTED_PAST 0x02
  13 +#define CONNECTED_NOW 0x01
  14 +
12 void dhcp_connect_result_cb(int result); 15 void dhcp_connect_result_cb(int result);
13 void wifi_connect_result_cb(int result); 16 void wifi_connect_result_cb(int result);
14 void wifi_connect_ap_result_cb(int result); 17 void wifi_connect_ap_result_cb(int result);
Project/applications/smartcities/include/i2c.h
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 11
12 #define DBG_I2C(fmt,...) printf("%c[1;35mi2c.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) 12 #define DBG_I2C(fmt,...) printf("%c[1;35mi2c.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__)
13 13
  14 +
14 void I2C_init(void); 15 void I2C_init(void);
15 void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction); 16 void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction);
16 void I2C_stop(I2C_TypeDef* I2Cx); 17 void I2C_stop(I2C_TypeDef* I2Cx);
Project/applications/smartcities/include/sensors.h
@@ -43,6 +43,7 @@ extern sensor* sensors[TOTAL_SENSORS+1]; @@ -43,6 +43,7 @@ extern sensor* sensors[TOTAL_SENSORS+1];
43 //SENSOR FUNCTIONS 43 //SENSOR FUNCTIONS
44 44
45 //LIGHT SENSOR 45 //LIGHT SENSOR
  46 +void init_light(void);
46 uint32_t get_light_data(void); 47 uint32_t get_light_data(void);
47 uint16_t get_light_ch0(void); 48 uint16_t get_light_ch0(void);
48 uint16_t get_light_ch1(void); 49 uint16_t get_light_ch1(void);
Project/applications/smartcities/json.c
@@ -178,7 +178,7 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen @@ -178,7 +178,7 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen
178 chHeapFree(URL); 178 chHeapFree(URL);
179 if(response_code == 200) 179 if(response_code == 200)
180 { 180 {
181 - DBG_JSON("Success: JSON_POST_OK\r\n"); 181 + DBG_JSON("Success: %c[1;32mJSON_POST_OK%c[1;00m\r\n",0x1B,0x1B);
182 return JSON_POST_OK; 182 return JSON_POST_OK;
183 } 183 }
184 else if((response_code >= 400) && (response_code < 500)) 184 else if((response_code >= 400) && (response_code < 500))
Project/applications/smartcities/main.c
@@ -31,13 +31,21 @@ void initLibwismart(void) @@ -31,13 +31,21 @@ void initLibwismart(void)
31 31
32 void update_time(unsigned long *time) 32 void update_time(unsigned long *time)
33 { 33 {
34 - DBG("Requesting new NTP time...\r\n");  
35 - unsigned long new_time = getSecsSince1900();  
36 - if(new_time) 34 + do
37 { 35 {
38 - *time = getSecsSince1900();  
39 - }  
40 - DBG("Time updated\r\n"); 36 + DBG("Requesting new NTP time...\r\n");
  37 + unsigned long new_time = getSecsSince1900();
  38 + if(new_time)
  39 + {
  40 + DBG("Updating new time to %ul\r\n",new_time);
  41 + *time = new_time;
  42 + DBG("Time updated\r\n");
  43 + }
  44 + else
  45 + {
  46 + DBG("%c[1;31m[ERROR] NTP query FAILED%c[1;00m\r\n",0x1B,0x1B);
  47 + }
  48 + }while(!(*time));
41 } 49 }
42 50
43 void init_registry(void) 51 void init_registry(void)
@@ -96,7 +104,7 @@ void init_registry(void) @@ -96,7 +104,7 @@ void init_registry(void)
96 libwismart_WiFiConnect(config.ssid,config.wepkey,wifi_connect_result_cb); 104 libwismart_WiFiConnect(config.ssid,config.wepkey,wifi_connect_result_cb);
97 libwismart_WiFiSetWep(config.wepkey,1); 105 libwismart_WiFiSetWep(config.wepkey,1);
98 } 106 }
99 - while(connected == 0 && timeout != 1 ) 107 + while((connected & CONNECTED_NOW) == 0 && timeout != 1 )
100 {chThdSleepMilliseconds(500);} 108 {chThdSleepMilliseconds(500);}
101 109
102 } 110 }
@@ -150,7 +158,7 @@ void wifi_connect(void) @@ -150,7 +158,7 @@ void wifi_connect(void)
150 { 158 {
151 DBG("Connecting wifi...\r\n"); 159 DBG("Connecting wifi...\r\n");
152 init_registry(); 160 init_registry();
153 - if(timeout==1) 161 + if(timeout==1 && (connected & CONNECTED_PAST) == 0)
154 { 162 {
155 DBG("Creating AP\r\n"); 163 DBG("Creating AP\r\n");
156 configServer_start(1); 164 configServer_start(1);
@@ -160,13 +168,13 @@ void wifi_connect(void) @@ -160,13 +168,13 @@ void wifi_connect(void)
160 chThdSleepMilliseconds(1000); 168 chThdSleepMilliseconds(1000);
161 } 169 }
162 } 170 }
  171 + timeout = 0;
163 } 172 }
164 173
165 void send_battery_level(unsigned long timestamp) 174 void send_battery_level(unsigned long timestamp)
166 { 175 {
167 DBG("Polling battery level...\r\n"); 176 DBG("Polling battery level...\r\n");
168 char *batt_level = battery_value(get_battery_data()); 177 char *batt_level = battery_value(get_battery_data());
169 - //char *batt_level = battery_value(3300);  
170 char *batt_data = timestamp_data(batt_level,getDate(timestamp)); 178 char *batt_data = timestamp_data(batt_level,getDate(timestamp));
171 chHeapFree(batt_level); 179 chHeapFree(batt_level);
172 char *statement = prepare_json_observation_statement(&batt_data,1); 180 char *statement = prepare_json_observation_statement(&batt_data,1);
@@ -183,7 +191,12 @@ void send_battery_level(unsigned long timestamp) @@ -183,7 +191,12 @@ void send_battery_level(unsigned long timestamp)
183 void wifi_disconnect(void) 191 void wifi_disconnect(void)
184 { 192 {
185 DBG("Disconnecting wifi...\r\n"); 193 DBG("Disconnecting wifi...\r\n");
186 - connected = 0; 194 + if(connected & CONNECTED_NOW)
  195 + {
  196 + connected |= CONNECTED_PAST;
  197 + }
  198 + connected = connected & CONNECTED_PAST ;
  199 + DBG("Connnected: %d\r\n",connected);
187 timeout = 0; 200 timeout = 0;
188 uint8_t res=libwismart_WiFiDisconnect(); 201 uint8_t res=libwismart_WiFiDisconnect();
189 if(res) 202 if(res)
@@ -206,7 +219,7 @@ int main(void) @@ -206,7 +219,7 @@ int main(void)
206 int j; 219 int j;
207 uint8_t sensors[TOTAL_SENSORS]; 220 uint8_t sensors[TOTAL_SENSORS];
208 char* valueSensors[TOTAL_SENSORS]; 221 char* valueSensors[TOTAL_SENSORS];
209 - unsigned long time; 222 + unsigned long time = 0;
210 unsigned long timestamp; 223 unsigned long timestamp;
211 unsigned long delay; 224 unsigned long delay;
212 uint32_t ind[TOTAL_SENSORS]={0}; 225 uint32_t ind[TOTAL_SENSORS]={0};
@@ -223,7 +236,6 @@ int main(void) @@ -223,7 +236,6 @@ int main(void)
223 } 236 }
224 237
225 DBG("%c[1;35m--------------WI-SENSE STARTED-------------%c[1;00m\r\n",0x1B,0x1B); 238 DBG("%c[1;35m--------------WI-SENSE STARTED-------------%c[1;00m\r\n",0x1B,0x1B);
226 -  
227 wifi_connect(); 239 wifi_connect();
228 check_memory(); 240 check_memory();
229 241
Project/applications/smartcities/ntp.c
@@ -109,11 +109,11 @@ unsigned long getSecsSince1900 (void) @@ -109,11 +109,11 @@ unsigned long getSecsSince1900 (void)
109 // If this is a SNTP response... 109 // If this is a SNTP response...
110 if (((sntp_response[0] & SNTP_MODE_MASK) == SNTP_MODE_SERVER) || ((sntp_response[0] & SNTP_MODE_MASK) == SNTP_MODE_BROADCAST)) 110 if (((sntp_response[0] & SNTP_MODE_MASK) == SNTP_MODE_SERVER) || ((sntp_response[0] & SNTP_MODE_MASK) == SNTP_MODE_BROADCAST))
111 { 111 {
  112 + DBG_NTP("Successfully got new time\r\n");
112 /* extract GMT time from response */ 113 /* extract GMT time from response */
113 memcpy(&timestamp, (sntp_response + SNTP_RCV_TIME_OFS), sizeof(timestamp)); 114 memcpy(&timestamp, (sntp_response + SNTP_RCV_TIME_OFS), sizeof(timestamp));
114 timestamp=(ntohl(timestamp)); 115 timestamp=(ntohl(timestamp));
115 -  
116 - DBG_NTP("Received timestamp %u\r\n", timestamp); 116 + DBG_NTP("Received timestamp %ul\r\n", timestamp);
117 } 117 }
118 else 118 else
119 { 119 {
@@ -165,10 +165,12 @@ unsigned long getSecsSince1900 (void) @@ -165,10 +165,12 @@ unsigned long getSecsSince1900 (void)
165 165
166 char* timestamp_data(char* value,Date time) 166 char* timestamp_data(char* value,Date time)
167 { 167 {
  168 + DBG_NTP("Writing timestamp...\r\n");
168 uint8_t length = strlen(value) + strlen(",00/00/0000T00:00:00") + 1; 169 uint8_t length = strlen(value) + strlen(",00/00/0000T00:00:00") + 1;
169 char str_day[3],str_month[3],str_year[5],str_hour[3],str_minute[3],str_second[3]; 170 char str_day[3],str_month[3],str_year[5],str_hour[3],str_minute[3],str_second[3];
  171 + DBG_NTP("Asking for %d bytes in timestamp_data\r\n", length);
170 char* data = chHeapAlloc(NULL,length*sizeof(char)); 172 char* data = chHeapAlloc(NULL,length*sizeof(char));
171 - 173 + DBG_NTP("Data allocated in timestamp_data\r\n", length);
172 sprintf(str_day,"%d",time.day); 174 sprintf(str_day,"%d",time.day);
173 sprintf(str_month,"%d",time.month); 175 sprintf(str_month,"%d",time.month);
174 sprintf(str_year,"%d",time.year); 176 sprintf(str_year,"%d",time.year);
Project/applications/smartcities/report 0 โ†’ 100644
  1 +main.c: --------------WI-SENSE STARTED-------------
  2 +main.c: Connecting wifi...
  3 +main.c: SSID = SERVER_WLAN
  4 +main.c: Wep key = TGW2YHNKT9TW
  5 +main.c: Passphrase = TGW2YHNKT9TW
  6 +main.c: User =
  7 +main.c: Password =
  8 +main.c: Encryption type = 4
  9 +main.c: Geo Localization = 41.557255 2.096183
  10 +main.c: WPA network detected
  11 +callbacks.c: WiFi Connect indication: Connected
  12 +Connected to: 00:26:5B:D9:0D:18
  13 +callbacks.c: IP: 192.168.0.47
  14 +buffer.c: Checking available memory...
  15 +buffer.c: Available memory: 33320 B
  16 +buffer.c: Used memory: 1384 B
  17 +sensors.c: Waking up sensors...
  18 +sensors.c: Woken Pin 3
  19 +sensors.c: Woken Pin 4
  20 +sensors.c: Woken Pin 5
  21 +sensors.c: Woken Pin 6
  22 +sensors.c: Woken Pin 7
  23 +i2c.c: Scanning sensors...
  24 +i2c.c: Initializing I2C...
  25 +i2c.c: Probing address 72 ...
  26 +i2c.c: Resetting I2C...
  27 +i2c.c: Initializing I2C...
  28 +i2c.c: Probing address 2 ...
  29 +i2c.c: Resetting I2C...
  30 +i2c.c: Initializing I2C...
  31 +i2c.c: Probing address EE ...
  32 +i2c.c: I2C address detected: EE
  33 +i2c.c: Sending I2C byte 00...
  34 +i2c.c: Data sent
  35 +i2c.c: Sending I2C Stop...
  36 +i2c.c: Stop sent
  37 +json.c: Registering sensor: Pressure sensor
  38 +json.c: Putting additional info for pressure sensor...
  39 +sensors.c: [PRESSURE] Fetching callibration data
  40 +i2c.c: Sending I2C Start...
  41 +i2c.c: I2C ready
  42 +i2c.c: Start sent
  43 +i2c.c: Start ACK
  44 +i2c.c: Master -> Slave Address and R/W sent
  45 +i2c.c: Slave -> Master ACK
  46 +i2c.c: Sending I2C byte AA...
  47 +i2c.c: Data sent
  48 +i2c.c: Sending repeated I2C Start...
  49 +i2c.c: Start sent
  50 +i2c.c: Start ACK
  51 +i2c.c: Master -> Slave Address and R/W sent
  52 +i2c.c: Slave -> Master ACK
  53 +i2c.c: Listening for byte in I2C (ACK)
  54 +i2c.c: Received byte: 1D
  55 +i2c.c: Listening for byte in I2C (NACK)
  56 +i2c.c: Received byte: 1D
  57 +i2c.c: Sending I2C Stop...
  58 +i2c.c: Stop sent
  59 +i2c.c: Sending I2C Start...
  60 +i2c.c: I2C ready
  61 +i2c.c: Start sent
  62 +i2c.c: Start ACK
  63 +i2c.c: Master -> Slave Address and R/W sent
  64 +i2c.c: Slave -> Master ACK
  65 +i2c.c: Sending I2C byte AC...
  66 +i2c.c: Data sent
  67 +i2c.c: Sending repeated I2C Start...
  68 +i2c.c: Start sent
  69 +i2c.c: Start ACK
  70 +i2c.c: Master -> Slave Address and R/W sent
  71 +i2c.c: Slave -> Master ACK
  72 +i2c.c: Listening for byte in I2C (ACK)
  73 +i2c.c: Received byte: FC
  74 +i2c.c: Listening for byte in I2C (NACK)
  75 +i2c.c: Received byte: FF
  76 +i2c.c: Sending I2C Stop...
  77 +i2c.c: Stop sent
  78 +i2c.c: Sending I2C Start...
  79 +i2c.c: I2C ready
  80 +i2c.c: Start sent
  81 +i2c.c: Start ACK
  82 +i2c.c: Master -> Slave Address and R/W sent
  83 +i2c.c: Slave -> Master ACK
  84 +i2c.c: Sending I2C byte AE...
  85 +i2c.c: Data sent
  86 +i2c.c: Sending repeated I2C Start...
  87 +i2c.c: Start sent
  88 +i2c.c: Start ACK
  89 +i2c.c: Master -> Slave Address and R/W sent
  90 +i2c.c: Slave -> Master ACK
  91 +i2c.c: Listening for byte in I2C (ACK)
  92 +i2c.c: Received byte: C7
  93 +i2c.c: Listening for byte in I2C (NACK)
  94 +i2c.c: Received byte: FF
  95 +i2c.c: Sending I2C Stop...
  96 +i2c.c: Stop sent
  97 +i2c.c: Sending I2C Start...
  98 +i2c.c: I2C ready
  99 +i2c.c: Start sent
  100 +i2c.c: Start ACK
  101 +i2c.c: Master -> Slave Address and R/W sent
  102 +i2c.c: Slave -> Master ACK
  103 +i2c.c: Sending I2C byte B0...
  104 +i2c.c: Data sent
  105 +i2c.c: Sending repeated I2C Start...
  106 +i2c.c: Start sent
  107 +i2c.c: Start ACK
  108 +i2c.c: Master -> Slave Address and R/W sent
  109 +i2c.c: Slave -> Master ACK
  110 +i2c.c: Listening for byte in I2C (ACK)
  111 +i2c.c: Received byte: 7D
  112 +i2c.c: Listening for byte in I2C (NACK)
  113 +i2c.c: Received byte: FF
  114 +i2c.c: Sending I2C Stop...
  115 +i2c.c: Stop sent
  116 +i2c.c: Sending I2C Start...
  117 +i2c.c: I2C ready
  118 +i2c.c: Start sent
  119 +i2c.c: Start ACK
  120 +i2c.c: Master -> Slave Address and R/W sent
  121 +i2c.c: Slave -> Master ACK
  122 +i2c.c: Sending I2C byte B2...
  123 +i2c.c: Data sent
  124 +i2c.c: Sending repeated I2C Start...
  125 +i2c.c: Start sent
  126 +i2c.c: Start ACK
  127 +i2c.c: Master -> Slave Address and R/W sent
  128 +i2c.c: Slave -> Master ACK
  129 +i2c.c: Listening for byte in I2C (ACK)
  130 +i2c.c: Received byte: 60
  131 +i2c.c: Listening for byte in I2C (NACK)
  132 +i2c.c: Received byte: FF
  133 +i2c.c: Sending I2C Stop...
  134 +i2c.c: Stop sent
  135 +i2c.c: Sending I2C Start...
  136 +i2c.c: I2C ready
  137 +i2c.c: Start sent
  138 +i2c.c: Start ACK
  139 +i2c.c: Master -> Slave Address and R/W sent
  140 +i2c.c: Slave -> Master ACK
  141 +i2c.c: Sending I2C byte B4...
  142 +i2c.c: Data sent
  143 +i2c.c: Sending repeated I2C Start...
  144 +i2c.c: Start sent
  145 +i2c.c: Start ACK
  146 +i2c.c: Master -> Slave Address and R/W sent
  147 +i2c.c: Slave -> Master ACK
  148 +i2c.c: Listening for byte in I2C (ACK)
  149 +i2c.c: Received byte: 4F
  150 +i2c.c: Listening for byte in I2C (NACK)
  151 +i2c.c: Received byte: FF
  152 +i2c.c: Sending I2C Stop...
  153 +i2c.c: Stop sent
  154 +i2c.c: Sending I2C Start...
  155 +i2c.c: I2C ready
  156 +i2c.c: Start sent
  157 +i2c.c: Start ACK
  158 +i2c.c: Master -> Slave Address and R/W sent
  159 +i2c.c: Slave -> Master ACK
  160 +i2c.c: Sending I2C byte B6...
  161 +i2c.c: Data sent
  162 +i2c.c: Sending repeated I2C Start...
  163 +i2c.c: Start sent
  164 +i2c.c: Start ACK
  165 +i2c.c: Master -> Slave Address and R/W sent
  166 +i2c.c: Slave -> Master ACK
  167 +i2c.c: Listening for byte in I2C (ACK)
  168 +i2c.c: Received byte: 15
  169 +i2c.c: Listening for byte in I2C (NACK)
  170 +i2c.c: Received byte: FF
  171 +i2c.c: Sending I2C Stop...
  172 +i2c.c: Stop sent
  173 +i2c.c: Sending I2C Start...
  174 +i2c.c: I2C ready
  175 +i2c.c: Start sent
  176 +i2c.c: Start ACK
  177 +i2c.c: Master -> Slave Address and R/W sent
  178 +i2c.c: Slave -> Master ACK
  179 +i2c.c: Sending I2C byte B8...
  180 +i2c.c: Data sent
  181 +i2c.c: Sending repeated I2C Start...
  182 +i2c.c: Start sent
  183 +i2c.c: Start ACK
  184 +i2c.c: Master -> Slave Address and R/W sent
  185 +i2c.c: Slave -> Master ACK
  186 +i2c.c: Listening for byte in I2C (ACK)
  187 +i2c.c: Received byte: 00
  188 +i2c.c: Listening for byte in I2C (NACK)
  189 +i2c.c: Received byte: FF
  190 +i2c.c: Sending I2C Stop...
  191 +i2c.c: Stop sent
  192 +i2c.c: Sending I2C Start...
  193 +i2c.c: I2C ready
  194 +i2c.c: Start sent
  195 +i2c.c: Start ACK
  196 +i2c.c: Master -> Slave Address and R/W sent
  197 +i2c.c: Slave -> Master ACK
  198 +i2c.c: Sending I2C byte BA...
  199 +i2c.c: Data sent
  200 +i2c.c: Sending repeated I2C Start...
  201 +i2c.c: Start sent
  202 +i2c.c: Start ACK
  203 +i2c.c: Master -> Slave Address and R/W sent
  204 +i2c.c: Slave -> Master ACK
  205 +i2c.c: Listening for byte in I2C (ACK)
  206 +i2c.c: Received byte: 80
  207 +i2c.c: Listening for byte in I2C (NACK)
  208 +i2c.c: Received byte: FF
  209 +i2c.c: Sending I2C Stop...
  210 +i2c.c: Stop sent
  211 +i2c.c: Sending I2C Start...
  212 +i2c.c: I2C ready
  213 +i2c.c: Start sent
  214 +i2c.c: Start ACK
  215 +i2c.c: Master -> Slave Address and R/W sent
  216 +i2c.c: Slave -> Master ACK
  217 +i2c.c: Sending I2C byte BC...
  218 +i2c.c: Data sent
  219 +i2c.c: Sending repeated I2C Start...
  220 +i2c.c: Start sent
  221 +i2c.c: Start ACK
  222 +i2c.c: Master -> Slave Address and R/W sent
  223 +i2c.c: Slave -> Master ACK
  224 +i2c.c: Listening for byte in I2C (ACK)
  225 +i2c.c: Received byte: D4
  226 +i2c.c: Listening for byte in I2C (NACK)
  227 +i2c.c: Received byte: FF
  228 +i2c.c: Sending I2C Stop...
  229 +i2c.c: Stop sent
  230 +i2c.c: Sending I2C Start...
  231 +i2c.c: I2C ready
  232 +i2c.c: Start sent
  233 +i2c.c: Start ACK
  234 +i2c.c: Master -> Slave Address and R/W sent
  235 +i2c.c: Slave -> Master ACK
  236 +i2c.c: Sending I2C byte BE...
  237 +i2c.c: Data sent
  238 +i2c.c: Sending repeated I2C Start...
  239 +i2c.c: Start sent
  240 +i2c.c: Start ACK
  241 +i2c.c: Master -> Slave Address and R/W sent
  242 +i2c.c: Slave -> Master ACK
  243 +i2c.c: Listening for byte in I2C (ACK)
  244 +i2c.c: Received byte: 09
  245 +i2c.c: Listening for byte in I2C (NACK)
  246 +i2c.c: Received byte: FF
  247 +i2c.c: Sending I2C Stop...
  248 +i2c.c: Stop sent
  249 +sensors.c: [PRESSURE] Got callibration data
  250 +json.c: callibration_data is: 7453,64767,51199,32255,24831,20479,5631,255,33023,54527,2559
  251 +json.c: In prepare_json_register_statement: Detected additional_info
  252 +json.c: Server is lewis.upc.es
  253 +httpClient.c: Checking params
  254 +httpClient.c: Calculating header size
  255 +httpClient.c: Building request head
  256 +httpClient.c: Adding content to request string
  257 +httpClient.c: Packet:
  258 +
  259 +PUT /modularsense/wordpress/opendata/catalog/register HTTP/1.1
  260 +Host: 147.83.39.240
  261 +Content-Type: application/json; charset=UTF-8
  262 +Content-Length: 210
  263 +
  264 +{"sensors":[{"sensor":"00000177","description":"Pressure sensor","type":"pressure","unit":"hPa","location":"41.557255 2.096183","additionalInfo":"7453,64767,51199,32255,24831,20479,5631,255,33023,54527,2559"}]}
  265 +
  266 +httpClient.c: Setting connection
  267 +httpClient.c: Establishing connection
  268 +httpClient.c: Sending request
  269 +httpClient.c: Write returned: 0
  270 +httpClient.c: Waiting for response
  271 +httpClient.c: Receive returned: 0
  272 +httpClient.c: Response received. Let's parse the information
  273 +httpClient.c: Response code: 200ย€+0
  274 +json.c: Success: JSON_POST_OK
  275 +i2c.c: Probing address 4E ...
  276 +i2c.c: Resetting I2C...
  277 +i2c.c: Initializing I2C...
  278 +i2c.c: Probing address E4 ...
  279 +i2c.c: Resetting I2C...
  280 +i2c.c: Initializing I2C...
  281 +json.c: Registering sensor: Battery Level
  282 +json.c: Server is lewis.upc.es
  283 +httpClient.c: Checking params
  284 +httpClient.c: Calculating header size
  285 +httpClient.c: Building request head
  286 +httpClient.c: Adding content to request string
  287 +httpClient.c: Packet:
  288 +
  289 +PUT /modularsense/wordpress/opendata/catalog/register HTTP/1.1
  290 +Host: 147.83.39.240
  291 +Content-Type: application/json; charset=UTF-8
  292 +Content-Length: 124
  293 +
  294 +{"sensors":[{"sensor":"00000100","description":"Battery Level","type":"power","unit":"mV","location":"41.557255 2.096183"}]}
  295 +
  296 +httpClient.c: Setting connection
  297 +httpClient.c: Establishing connection
  298 +httpClient.c: Sending request
  299 +httpClient.c: Write returned: 0
  300 +httpClient.c: Waiting for response
  301 +httpClient.c: Receive returned: 0
  302 +httpClient.c: Response received. Let's parse the information
  303 +httpClient.c: Response code: 200
  304 +json.c: Success: JSON_POST_OK
  305 +main.c: 1 sensor detected...
  306 +main.c: Requesting new NTP time...
  307 +ntp.c: Successfully got new time
  308 +ntp.c: Received timestamp 3610877978
  309 +main.c: Updating new time to 3610877978
  310 +main.c: Time updated
  311 +main.c: Disconnecting wifi...
  312 +main.c: Disconnecting Successful: WIFI_DISCONNECT_SUCCESS
  313 +timer-loop.c: Time to sleep! for 22 seconds
  314 +callbacks.c: WiFi Connect indication: Failed
  315 +main.c: Time (absolute): 3610878000
  316 +Time LONG_PERIOD: 0
  317 +Time SHORT_PERIOD: 0
  318 +sensors.c: Collecting data...
  319 +sensors.c: Not freeing memory on index 0
  320 +sensors.c: Fetching data from pressure sensor
  321 +i2c.c: Sending I2C Start...
  322 +i2c.c: I2C ready
  323 +i2c.c: Start sent
  324 +i2c.c: Start ACK
  325 +i2c.c: Master -> Slave Address and R/W sent
  326 +i2c.c: Slave -> Master ACK
  327 +i2c.c: Sending I2C byte F4...
  328 +i2c.c: Data sent
  329 +i2c.c: Sending I2C byte 34...
  330 +i2c.c: Data sent
  331 +i2c.c: Sending I2C Stop...
  332 +i2c.c: Stop sent
  333 +sensors.c: [PRESSURE] Initialized
  334 +i2c.c: Sending I2C Start...
  335 +i2c.c: I2C ready
  336 +i2c.c: Start sent
  337 +i2c.c: Start ACK
  338 +i2c.c: Master -> Slave Address and R/W sent
  339 +i2c.c: Slave -> Master ACK
  340 +i2c.c: Sending I2C byte F6...
  341 +i2c.c: Data sent
  342 +i2c.c: Sending repeated I2C Start...
  343 +i2c.c: Start sent
  344 +i2c.c: Start ACK
  345 +i2c.c: Master -> Slave Address and R/W sent
  346 +i2c.c: Slave -> Master ACK
  347 +i2c.c: Listening for byte in I2C (ACK)
  348 +i2c.c: Received byte: 98
  349 +sensors.c: [PRESSURE] Got high byte
  350 +i2c.c: Listening for byte in I2C (NACK)
  351 +i2c.c: Received byte: C6
  352 +sensors.c: [PRESSURE] Got low byte
  353 +i2c.c: Sending I2C Stop...
  354 +i2c.c: Stop sent
  355 +i2c.c: Sending I2C Start...
  356 +i2c.c: I2C ready
  357 +i2c.c: Start sent
  358 +i2c.c: Start ACK
  359 +i2c.c: Master -> Slave Address and R/W sent
  360 +i2c.c: Slave -> Master ACK
  361 +i2c.c: Sending I2C byte F4...
  362 +i2c.c: Data sent
  363 +i2c.c: Sending I2C byte 2E...
  364 +i2c.c: Data sent
  365 +i2c.c: Sending I2C Stop...
  366 +i2c.c: Stop sent
  367 +sensors.c: [PRESSURE] Initialized temperature
  368 +i2c.c: Sending I2C Start...
  369 +i2c.c: I2C ready
  370 +i2c.c: Start sent
  371 +i2c.c: Start ACK
  372 +i2c.c: Master -> Slave Address and R/W sent
  373 +i2c.c: Slave -> Master ACK
  374 +i2c.c: Sending I2C byte F6...
  375 +i2c.c: Data sent
  376 +i2c.c: Sending repeated I2C Start...
  377 +i2c.c: Start sent
  378 +i2c.c: Start ACK
  379 +i2c.c: Master -> Slave Address and R/W sent
  380 +i2c.c: Slave -> Master ACK
  381 +i2c.c: Listening for byte in I2C (ACK)
  382 +i2c.c: Received byte: 71
  383 +sensors.c: [PRESSURE] Got temperature high byte
  384 +i2c.c: Listening for byte in I2C (NACK)
  385 +i2c.c: Received byte: FF
  386 +sensors.c: [PRESSURE] Got temperature low byte
  387 +i2c.c: Sending I2C Stop...
  388 +i2c.c: Stop sent
  389 +sensors.c: Data collected
  390 +main.c: Time (absolute): 3610878000
  391 +Time LONG_PERIOD: 0
  392 +Time SHORT_PERIOD: 0
  393 +main.c: Timestamp (absolute): 3610878000
  394 +Timestamp LONG_PERIOD: 0
  395 +Timestamp SHORT_PERIOD: 0
  396 +main.c: Timestamping data...
  397 +main.c: Data is: 39110,29183,4/6/2014T15:40:0
  398 +main.c: Returning timestamped data...
  399 +main.c: Putting data in buffers...
  400 +main.c: Putting data: 39110,29183,4/6/2014T15:40:0
  401 + buffer.c: Joining buffer...
  402 +buffer.c: Start buffer join...
  403 +buffer.c: All data transferred
  404 +buffer.c: Old buffer cleared
  405 +buffer.c: Joined buffer...
  406 +buffer.c: Memory allocated...
  407 +buffer.c: Data copied...
  408 +main.c: Message put: 39110,29183,4/6/2014T15:40:0
  409 +main.c: Memory freed
  410 + main.c: [ASSERTION] Message put: 39110,29183,4/6/2014T15:40:0 with length 28
  411 +main.c: Data is now in buffer
  412 + buffer.c: Checking available memory...
  413 +buffer.c: Available memory: 1859003 B
  414 +buffer.c: Used memory: -1824299 B
  415 +main.c: Time (absolute): 3610878000
  416 +Time LONG_PERIOD: 0
  417 +Time SHORT_PERIOD: 0
  418 +timer-loop.c: Time to sleep! for 60 seconds
Project/applications/smartcities/sensors.c
@@ -74,15 +74,39 @@ void wakeup_sensors(uint8_t logic_address) @@ -74,15 +74,39 @@ void wakeup_sensors(uint8_t logic_address)
74 } 74 }
75 } 75 }
76 76
  77 +void init_light(void)
  78 +{
  79 + I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
  80 + I2C_write(I2C1, 0x80);
  81 + I2C_write(I2C1, 0x03);
  82 + I2C_stop(I2C1);
  83 + DBG_SENSORS("[LIGHT] Sent power on command\r\n");
  84 +
  85 + I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
  86 + I2C_write(I2C1, 0x81);
  87 + I2C_write(I2C1, 0x0A);
  88 + I2C_stop(I2C1);
  89 + DBG_SENSORS("[LIGHT] Sent start conversion command\r\n");
  90 + chThdSleepMilliseconds(500);
  91 +
  92 + I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
  93 + I2C_write(I2C1, 0x81);
  94 + I2C_write(I2C1, 0x02);
  95 + I2C_stop(I2C1);
  96 + DBG_SENSORS("[LIGHT] Sent stop conversion command\r\n");
  97 +}
  98 +
77 uint32_t get_light_data(void) 99 uint32_t get_light_data(void)
78 { 100 {
  101 + init_light();
79 uint32_t data = 0; 102 uint32_t data = 0;
80 -  
81 data = get_light_ch1(); 103 data = get_light_ch1();
82 DBG_SENSORS("[LIGHT] Got ch1\r\n"); 104 DBG_SENSORS("[LIGHT] Got ch1\r\n");
83 data = data << 16; 105 data = data << 16;
84 data = data | get_light_ch0(); 106 data = data | get_light_ch0();
85 DBG_SENSORS("[LIGHT] Got ch0\r\n"); 107 DBG_SENSORS("[LIGHT] Got ch0\r\n");
  108 + DBG_SENSORS("[LIGHT] CH1 = %02x\r\n",(data & 0xFFFF0000) >> 16);
  109 + DBG_SENSORS("[LIGHT] CH0 = %02x\r\n",data & 0x0000FFFF);
86 return data; 110 return data;
87 } 111 }
88 uint16_t get_light_ch0(void) 112 uint16_t get_light_ch0(void)
@@ -90,15 +114,21 @@ uint16_t get_light_ch0(void) @@ -90,15 +114,21 @@ uint16_t get_light_ch0(void)
90 uint16_t data = 0; 114 uint16_t data = 0;
91 115
92 I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); 116 I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
93 - I2C_write(I2C1, 0x0C);  
94 - DBG_SENSORS("[LIGHT] Sent fetch command for CH1\r\n"); 117 + I2C_write(I2C1, 0x8C);
  118 + DBG_SENSORS("[LIGHT] Sent fetch command for CH0\r\n");
  119 +
  120 + I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver);
  121 + data = I2C_read_nack(I2C1);
  122 + I2C_stop(I2C1);
  123 + DBG_SENSORS("[LIGHT] Got low byte for CH0\r\n");
  124 +
  125 + I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
  126 + I2C_write(I2C1, 0x8D);
95 127
96 I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); 128 I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver);
97 - data = I2C_read_ack(I2C1);  
98 - DBG_SENSORS("[LIGHT] Got low byte for CH1\r\n");  
99 data = data | (I2C_read_nack(I2C1) << 8); 129 data = data | (I2C_read_nack(I2C1) << 8);
100 - DBG_SENSORS("[LIGHT] Got high byte for CH1\r\n");  
101 I2C_stop(I2C1); 130 I2C_stop(I2C1);
  131 + DBG_SENSORS("[LIGHT] Got high byte for CH0\r\n");
102 132
103 return data; 133 return data;
104 } 134 }
@@ -107,23 +137,29 @@ uint16_t get_light_ch1(void) @@ -107,23 +137,29 @@ uint16_t get_light_ch1(void)
107 uint16_t data = 0; 137 uint16_t data = 0;
108 138
109 I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter); 139 I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
110 - I2C_write(I2C1, 0x0E); 140 + I2C_write(I2C1, 0x8E);
111 DBG_SENSORS("[LIGHT] Sent fetch command for CH1\r\n"); 141 DBG_SENSORS("[LIGHT] Sent fetch command for CH1\r\n");
112 142
113 I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver); 143 I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver);
114 - data = I2C_read_ack(I2C1); 144 + data = I2C_read_nack(I2C1);
  145 + I2C_stop(I2C1);
115 DBG_SENSORS("[LIGHT] Got low byte for CH1\r\n"); 146 DBG_SENSORS("[LIGHT] Got low byte for CH1\r\n");
  147 +
  148 + I2C_start(I2C1,LIGHT_ADDR << 1, I2C_Direction_Transmitter);
  149 + I2C_write(I2C1, 0x8F);
  150 +
  151 + I2C_restart(I2C1, LIGHT_ADDR << 1, I2C_Direction_Receiver);
116 data = data | (I2C_read_nack(I2C1) << 8); 152 data = data | (I2C_read_nack(I2C1) << 8);
  153 + I2C_stop(I2C1);
117 DBG_SENSORS("[LIGHT] Got high byte for CH1\r\n"); 154 DBG_SENSORS("[LIGHT] Got high byte for CH1\r\n");
118 - I2C_stop(I2C1);  
119 - 155 +
120 return data; 156 return data;
121 } 157 }
122 158
123 char* light_value(uint32_t light) 159 char* light_value(uint32_t light)
124 { 160 {
125 char *value = chHeapAlloc(NULL,10 + 1); 161 char *value = chHeapAlloc(NULL,10 + 1);
126 - sprintf(value,"%d",(unsigned int)light); 162 + sprintf(value,"%u",(unsigned int)light);
127 return value; 163 return value;
128 } 164 }
129 165
@@ -159,7 +195,7 @@ uint16_t get_distance_data(void) @@ -159,7 +195,7 @@ uint16_t get_distance_data(void)
159 char* distance_value(uint16_t distance) 195 char* distance_value(uint16_t distance)
160 { 196 {
161 char *value = chHeapAlloc(NULL,5 + 1); 197 char *value = chHeapAlloc(NULL,5 + 1);
162 - sprintf(value,"%d",distance); 198 + sprintf(value,"%u",distance);
163 return value; 199 return value;
164 } 200 }
165 201
@@ -273,17 +309,17 @@ char* callibration_pressure_data_csv(bmp085_callibration parameters) @@ -273,17 +309,17 @@ char* callibration_pressure_data_csv(bmp085_callibration parameters)
273 { 309 {
274 char *str = chHeapAlloc(NULL,sizeof(char)*(11*11-1)); 310 char *str = chHeapAlloc(NULL,sizeof(char)*(11*11-1));
275 memset(str,0x00,sizeof(char)*(11*11)); 311 memset(str,0x00,sizeof(char)*(11*11));
276 - sprintf(str + strlen(str),"%d,",parameters.AC1);  
277 - sprintf(str + strlen(str),"%d,",parameters.AC2);  
278 - sprintf(str + strlen(str),"%d,",parameters.AC3);  
279 - sprintf(str + strlen(str),"%d,",parameters.AC4);  
280 - sprintf(str + strlen(str),"%d,",parameters.AC5);  
281 - sprintf(str + strlen(str),"%d,",parameters.AC6);  
282 - sprintf(str + strlen(str),"%d,",parameters.B1);  
283 - sprintf(str + strlen(str),"%d,",parameters.B2);  
284 - sprintf(str + strlen(str),"%d,",parameters.MB);  
285 - sprintf(str + strlen(str),"%d,",parameters.MC);  
286 - sprintf(str + strlen(str),"%d",parameters.MD); 312 + sprintf(str + strlen(str),"%u,",parameters.AC1);
  313 + sprintf(str + strlen(str),"%u,",parameters.AC2);
  314 + sprintf(str + strlen(str),"%u,",parameters.AC3);
  315 + sprintf(str + strlen(str),"%u,",parameters.AC4);
  316 + sprintf(str + strlen(str),"%u,",parameters.AC5);
  317 + sprintf(str + strlen(str),"%u,",parameters.AC6);
  318 + sprintf(str + strlen(str),"%u,",parameters.B1);
  319 + sprintf(str + strlen(str),"%u,",parameters.B2);
  320 + sprintf(str + strlen(str),"%u,",parameters.MB);
  321 + sprintf(str + strlen(str),"%u,",parameters.MC);
  322 + sprintf(str + strlen(str),"%u",parameters.MD);
287 return str; 323 return str;
288 } 324 }
289 325
@@ -326,7 +362,7 @@ uint16_t get_pressure_temperature_data(void) @@ -326,7 +362,7 @@ uint16_t get_pressure_temperature_data(void)
326 char* pressure_value(uint16_t pressure, uint16_t temperature) 362 char* pressure_value(uint16_t pressure, uint16_t temperature)
327 { 363 {
328 char *value = chHeapAlloc(NULL,11 + 1); 364 char *value = chHeapAlloc(NULL,11 + 1);
329 - sprintf(value,"%d,%d",pressure,temperature); 365 + sprintf(value,"%u,%u",pressure,temperature);
330 return value; 366 return value;
331 } 367 }
332 368
@@ -373,7 +409,7 @@ uint16_t get_temperature_data(void) @@ -373,7 +409,7 @@ uint16_t get_temperature_data(void)
373 char* temp_humidity_value(uint16_t temp, uint16_t humidity) 409 char* temp_humidity_value(uint16_t temp, uint16_t humidity)
374 { 410 {
375 char *value = chHeapAlloc(NULL,11 + 1); 411 char *value = chHeapAlloc(NULL,11 + 1);
376 - sprintf(value,"%d,%d",temp,humidity); 412 + sprintf(value,"%u,%u",temp,humidity);
377 return value; 413 return value;
378 } 414 }
379 415