diff --git a/Project/applications/smartcities/buffer.c b/Project/applications/smartcities/buffer.c index dd89864..137f9f5 100644 --- a/Project/applications/smartcities/buffer.c +++ b/Project/applications/smartcities/buffer.c @@ -20,7 +20,7 @@ char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len) } else { - DBG_BUFFER("WTF in put_message\r\n"); + DBG_BUFFER("%c[1;31m[ERROR] WTF in put_message%c[1;00m\r\n",0x1B,0x1B); buf[*index] = chHeapAlloc(NULL,strlen(info)+1); buf[*index] = info; i = *index+1; @@ -37,12 +37,12 @@ int check_memory() DBG_BUFFER("%c[1;36mUsed memory: %d B%c[1;00m\r\n",0x1B,mem,0x1B); if(mem >= HARD_LIMIT) { - DBG_BUFFER("[WARNING] Hard limit reached\r\n"); + DBG_BUFFER("%c[1;33m[WARNING] Hard limit reached%c[1;00m\r\n",0x1B,0x1B); return HARD_REACHED; } else if(mem >= SOFT_LIMIT) { - DBG_BUFFER("[WARNING] Soft limit reached\r\n"); + DBG_BUFFER("%c[1;33m[WARNING] Soft limit reached%c[1;00m\r\n",0x1B,0x1B); return SOFT_REACHED; } return MEMORY_OK; @@ -55,7 +55,7 @@ int send(char** buf, uint32_t *index, uint32_t *size_buf, char *provider_ID, cha uint32_t size = strlen(statement); if(buf==NULL) { - DBG_BUFFER("[ERROR] Buffer not initialized!\r\n"); + DBG_BUFFER("%c[1;31m[ERROR] Buffer not initialized!%c[1;00m\r\n",0x1B,0x1B); return 2; } uint8_t res = send_json(statement, size, provider_ID, sensor_ID); diff --git a/Project/applications/smartcities/callbacks.c b/Project/applications/smartcities/callbacks.c index 78073cf..2d47ec9 100644 --- a/Project/applications/smartcities/callbacks.c +++ b/Project/applications/smartcities/callbacks.c @@ -12,12 +12,12 @@ void dhcp_connect_result_cb(int result) } else if(result==LIBWISMART_DHCP_TIMEOUT) { - DBG_CALLBACKS("DHCP timeout\r\n"); + DBG_CALLBACKS("%c[1;31m[ERROR] DHCP timeout%c[1;00m\r\n",0x1B,0x1B); timeout = 1; } else { - DBG_CALLBACKS("DHCP error\r\n"); + DBG_CALLBACKS("%c[1;31m[ERROR] DHCP failed%c[1;00m\r\n",0x1B,0x1B); timeout = 1; } @@ -32,12 +32,12 @@ void wifi_connect_result_cb(int result) DBG_CALLBACKS("WiFi Connect indication: "); if(result == WISMART_WIFI_CONNECTED) { - printf("Connected\r\n"); + printf("%c[1;32mConnected%c[1;00m\r\n",0x1B,0x1B); retries = 0; } else { - printf("Failed\r\n"); + printf("%c[1;31mFailed%c[1;00m\r\n",0x1B,0x1B); if(++retries == MAX_RETRIES) { timeout = 1; diff --git a/Project/applications/smartcities/httpClient.c b/Project/applications/smartcities/httpClient.c index 793c8ac..b0b7666 100644 --- a/Project/applications/smartcities/httpClient.c +++ b/Project/applications/smartcities/httpClient.c @@ -77,13 +77,13 @@ int httpRequest(struct httpHeaders head, char* content, int content_size) { DBG_HTTP("Skipping void content\r\n"); } - DBG_HTTP("Packet:\r\n\r\n%c[1;33m%s%c[1;00m \r\n\r\n",0x1B,request,0x1B); + DBG_HTTP("Packet:\r\n\r\n%c[1;32m%s%c[1;00m \r\n\r\n",0x1B,request,0x1B); // Set connection DBG_HTTP("Setting connection\r\n"); neocon = netconn_new(NETCONN_TCP); if(neocon == NULL) - { - DBG_HTTP("[ERROR] Socket creation FAILED. Have you called libwismart_EnableBsdSocketAPI()?\r\n"); + { + DBG_HTTP("%c[1;31m[ERROR] Socket creation FAILED. Have you called libwismart_EnableBsdSocketAPI()?%c[1;00m\r\n",0x1B,0x1B); } /*local_ip.addr = 0;//getip netconn_bind(neocon, IP_ADDR_ANY, LOCAL_PORT); //88 is provisional local port.*/ diff --git a/Project/applications/smartcities/include/adc.h b/Project/applications/smartcities/include/adc.h index c66f7e6..1c39263 100644 --- a/Project/applications/smartcities/include/adc.h +++ b/Project/applications/smartcities/include/adc.h @@ -7,7 +7,7 @@ #include "stm32f10x_gpio.h" #include "stm32f10x_adc.h" -#define DBG_ADC(fmt,...) printf("%c[1;31madc.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG_ADC(fmt,...) printf("%c[1;35madc.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) #define ADCbatt_MIN_VALUE (0) #define ADCbatt_MAX_VALUE (0xfff) diff --git a/Project/applications/smartcities/include/buffer.h b/Project/applications/smartcities/include/buffer.h index 23a0e09..c7e9f00 100644 --- a/Project/applications/smartcities/include/buffer.h +++ b/Project/applications/smartcities/include/buffer.h @@ -10,7 +10,7 @@ #define SOFT_REACHED 1 #define HARD_REACHED 2 -#define DBG_BUFFER(fmt,...) printf("%c[1;31mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG_BUFFER(fmt,...) printf("%c[1;35mbuffer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) char** put_message(char* info, char** buf,uint32_t *index, uint32_t *buf_len); int check_memory(void); diff --git a/Project/applications/smartcities/include/callbacks.h b/Project/applications/smartcities/include/callbacks.h index 81a5ddb..42d05d5 100644 --- a/Project/applications/smartcities/include/callbacks.h +++ b/Project/applications/smartcities/include/callbacks.h @@ -17,7 +17,7 @@ void softapMode_clientIndicationCb(wismart_softap_cb_t reason, const uint8_t *ma void softapMode_apStartedCb(int result); void printWifiInfo(uint8_t wifiMode); -#define DBG_CALLBACKS(fmt,...) printf("%c[1;31mcallbacks.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG_CALLBACKS(fmt,...) printf("%c[1;35mcallbacks.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) extern uint8_t connected; extern uint8_t timeout; diff --git a/Project/applications/smartcities/include/configServer.h b/Project/applications/smartcities/include/configServer.h index f523d7e..479434a 100644 --- a/Project/applications/smartcities/include/configServer.h +++ b/Project/applications/smartcities/include/configServer.h @@ -10,8 +10,8 @@ #include "ch.h" #include "fsdata.c" -#define CONFIG_SERVER_DBG(fmt,...) printf("%c[1;31mconfigServer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) -#define CONFIG_SERVER_DBG_WARNING(fmt,...) printf("%c[1;31mconfigServer.c:%c[1;00m [WARNING] "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define CONFIG_SERVER_DBG(fmt,...) printf("%c[1;35mconfigServer.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define CONFIG_SERVER_DBG_WARNING(fmt,...) printf("%c[1;35mconfigServer.c:%c[1;33m[WARNING] "fmt"%c[1;00m",0x1B,0x1B,0x1B, ##__VA_ARGS__) void configServer_start(uint8_t enableApScan); void configServer_connect(void); diff --git a/Project/applications/smartcities/include/httpClient.h b/Project/applications/smartcities/include/httpClient.h index 868e42a..db1a0e4 100644 --- a/Project/applications/smartcities/include/httpClient.h +++ b/Project/applications/smartcities/include/httpClient.h @@ -14,15 +14,12 @@ #include "ch.h" #include "globals.h" -/* - * No fem servir DEFAULT_REMOTE_IP. Fem servir en canvi SERVER_IP, definida a globals.h - */ #define DEFAULT_REMOTE_IP "147.83.2.135" // www.upc.edu #define DEFAULT_REMOTE_PORT 80 #define ENDL "\r\n" #define CONTENT_TYPE_HEADER "Content-Type: application/json; charset=UTF-8" -#define DBG_HTTP(fmt,...) printf("%c[1;31mhttpClient.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG_HTTP(fmt,...) printf("%c[1;35mhttpClient.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) typedef enum reqMethod @@ -51,24 +48,4 @@ char* int2string(int num); int numberofdigits(int number); int response2int(char* chars); -#endif - -/* - -------------- -Sentilo codes -------------- - -Error Code HTTP Description -200 Success Request accepted and processed correctly -4xx Client Error Error in request (Wrong format, forbidden mandatory parameters, ...) -401 Unauthorized Unauthorized request: empty or invalid credential -403 Forbidden Not authorized for the requested action -5xx Server Error Error processing the request - -PUT - Publish sensor data -DELETE - Erase sensor data -GET - Download sensor data -(POST - create new sensor or publisher?) - -*/ +#endif \ No newline at end of file diff --git a/Project/applications/smartcities/include/i2c.h b/Project/applications/smartcities/include/i2c.h index 193da8c..bd082f1 100644 --- a/Project/applications/smartcities/include/i2c.h +++ b/Project/applications/smartcities/include/i2c.h @@ -9,7 +9,7 @@ #define I2C_TIMEOUT 100 -#define DBG_I2C(fmt,...) printf("%c[1;31mi2c.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG_I2C(fmt,...) printf("%c[1;35mi2c.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) void I2C_init(void); void I2C_start(I2C_TypeDef* I2Cx, uint8_t address, uint8_t direction); diff --git a/Project/applications/smartcities/include/json.h b/Project/applications/smartcities/include/json.h index 252f7a9..dbb85a5 100644 --- a/Project/applications/smartcities/include/json.h +++ b/Project/applications/smartcities/include/json.h @@ -18,7 +18,7 @@ #define JOIN_NO_FREE 0 #define JOIN_FREE_MEM 1 -#define DBG_JSON(fmt,...) printf("%c[1;31mjson.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG_JSON(fmt,...) printf("%c[1;35mjson.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) uint8_t register_sensor(sensor sens); char* prepare_json_observation_statement(char** data, uint32_t nObservations); diff --git a/Project/applications/smartcities/include/ntp.h b/Project/applications/smartcities/include/ntp.h index a3bf709..0362428 100644 --- a/Project/applications/smartcities/include/ntp.h +++ b/Project/applications/smartcities/include/ntp.h @@ -18,7 +18,7 @@ #include "ch.h" #include "globals.h" -#define DBG_NTP(fmt,...) printf("%c[1;31mntp.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG_NTP(fmt,...) printf("%c[1;35mntp.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) #define LEAP_YEAR(Y) (((1970+Y)>0) && !((1970+Y)%4) && (((1970+Y)%100) || !((1970+Y)%400))) #define NTP_PACKET_LENGTH 48 diff --git a/Project/applications/smartcities/include/sensors.h b/Project/applications/smartcities/include/sensors.h index 6500ea6..c5c489e 100644 --- a/Project/applications/smartcities/include/sensors.h +++ b/Project/applications/smartcities/include/sensors.h @@ -19,7 +19,7 @@ #define BATTERY_ADDR 0x00 //SIEMPRE PRESENTE, NUNCA BUSCAR EN i2c_scan -#define DBG_SENSORS(fmt,...) printf("%c[1;31msensors.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG_SENSORS(fmt,...) printf("%c[1;35msensors.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) typedef struct { uint8_t ID; diff --git a/Project/applications/smartcities/include/timer-loop.h b/Project/applications/smartcities/include/timer-loop.h index 1b993fb..9c4a8b2 100644 --- a/Project/applications/smartcities/include/timer-loop.h +++ b/Project/applications/smartcities/include/timer-loop.h @@ -11,7 +11,7 @@ #define LONG_PERIOD 60*3 //60*3 // for testing #define SHORT_PERIOD 60*1 //60*1 // for testing -#define DBG_TIMER(fmt,...) printf("%c[1;31mtimer-loop.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG_TIMER(fmt,...) printf("%c[1;35mtimer-loop.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) unsigned long getSystemTime(void); diff --git a/Project/applications/smartcities/json.c b/Project/applications/smartcities/json.c index ffed7b4..a0f830e 100644 --- a/Project/applications/smartcities/json.c +++ b/Project/applications/smartcities/json.c @@ -183,12 +183,13 @@ uint8_t send_json(char* statement, uint32_t length, char* provider_ID, char* sen } else if((response_code >= 400) && (response_code < 500)) { - DBG_JSON("[ERROR] Communication with server FAILED: JSON_COMM_ERROR\r\n"); + + DBG_JSON("%c[1;31m[ERROR] Communication with server FAILED: JSON_COMM_ERROR%c[1;00m\r\n",0x1B,0x1B); return JSON_COMM_ERROR; } else { - DBG_JSON("[ERROR] Unspecified error: JSON_ERROR_OTHER\r\n"); + DBG_JSON("%c[1;31m[ERROR] Unspecified error: JSON_ERROR_OTHER%c[1;00m\r\n",0x1B,0x1B); return JSON_OTHER_ERROR; } } diff --git a/Project/applications/smartcities/main.c b/Project/applications/smartcities/main.c index ba32414..5a46fdf 100644 --- a/Project/applications/smartcities/main.c +++ b/Project/applications/smartcities/main.c @@ -12,7 +12,7 @@ #include "ntp.h" #include "sensors.h" -#define DBG(fmt,...) printf("%c[1;31mmain.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) +#define DBG(fmt,...) printf("%c[1;35mmain.c:%c[1;00m "fmt,0x1B,0x1B, ##__VA_ARGS__) uint8_t connected=0; uint8_t timeout=0; @@ -126,6 +126,7 @@ void put_buffers(char** buffers[],uint32_t ind[],uint32_t sizes[],char** cooked, DBG("Memory freed\n\r"); DBG("[ASSERTION] Message put: %s with length %d\r\n",buffers[i][ind[i]-1] ,strlen(buffers[i][ind[i]-1])); } + DBG("Data is now in buffer\n\r"); } char** timestamp_datas(char* value[],unsigned long timestamp, uint8_t* sensors) { @@ -172,7 +173,10 @@ void send_battery_level(unsigned long timestamp) chHeapFree(batt_data); char id[3]; sprintf(id,"%02x",battery.ID); - send_json(statement,strlen(statement),mod.ID,id); + if(send_json(statement,strlen(statement),mod.ID,id) != JSON_POST_OK) + { + DBG("%c[1;31m[ERROR] Battery level NOT sent to server due to communication error%c[1;00m\r\n",0x1B,0x1B); + } chHeapFree(statement); } @@ -254,7 +258,6 @@ int main(void) delay = getSystemTime(); values=timestamp_datas(valueSensors,timestamp,sensors); put_buffers(buffers,ind,sizes,values,sensors); - DBG("Data is now in buffer\n\r"); if (i == LONG_PERIOD/SHORT_PERIOD ) { DBG("Programmed send cycle...\r\n"); @@ -288,8 +291,7 @@ int main(void) // El servidor no ens sap dir si tenim permisos o no sense registrar una mostra. // Intentem enviar un buffer sencer, a veure si ja podem buidar. // No podem enviar només una mostra perquè json és rígid en aquest sentit. - - DBG("[HARD LIMIT] unable to send\r\n"); + DBG("%c[1;31m[HARD LIMIT] unable to send%c[1;00m\r\n",0x1B,0x1B); chThdSleepMilliseconds(HARD_LIMIT_WAIT_TIME); } for(j=1;j