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