diff --git a/IHM_Local/main.c b/IHM_Local/main.c index 8506ce4..68eded5 100644 --- a/IHM_Local/main.c +++ b/IHM_Local/main.c @@ -36,12 +36,20 @@ void *myThreadFun(void *vargp) { cmd[1] = GET_ANALOG_INPUT_VALUE; //printf("Não analog cmd: \n"); publish(data->client, "comand", (char*) cmd); - await(20); + await(*data->update_interval); char history[255]; //printf("Não anl his: \n"); publish(data->client, "analogic/history", queue_to_string(leituras, &history)); - await(20); + await(*data->update_interval); + } + + if (1) { + char up[20] = "\0\0\0\0\0\0\0"; + sprintf(up, "%i", *data->update_interval); + publish(data->client, "update_interval", up); + up[20] = "\0\0\0\0\0\0\0"; + await(*data->update_interval); } /** @@ -56,9 +64,9 @@ void *myThreadFun(void *vargp) { char topic[255]; sprintf(topic, "%i/history", cmd[1]); //printf("Não dig his: \n"); - await(20); + await(*data->update_interval); publish(data->client, topic, queue_to_string(leituras, &history)); - await(20); // Aguarda comando ser processado + await(*data->update_interval); // Aguarda comando ser processado //serialReadBytes(ler); // lê resposta } } @@ -112,6 +120,7 @@ int main(int argc, char *argv[]) { conn_opts.cleansession = 1; conn_opts.username = USERNAME; conn_opts.password = PASSWORD; + int hhtt = 20; Sensor analogico; @@ -122,6 +131,7 @@ int main(int argc, char *argv[]) { data.digitals = digital; data.digitalQtd = &digitalQtd; data.verif = 753; + data.update_interval = &hhtt; data.MQTT_CONFIG = &conn_opts; @@ -135,6 +145,7 @@ int main(int argc, char *argv[]) { printf("conectado!!\n\n"); } MQTTClient_subscribe(data.client, MQTT_SUBSCRIBE_TOPIC, 0); + MQTTClient_subscribe(data.client, "nwUP", 0); printf("Fim da configuração do mqtt em: %p\n", &data); /*****************************************************************/ diff --git a/IHM_Local/makefile b/IHM_Local/makefile index a5e7ae0..1433612 100644 --- a/IHM_Local/makefile +++ b/IHM_Local/makefile @@ -10,7 +10,7 @@ list: all all: Rasp Rasp: Rasp.o display.o serial.o comunication.o sensor.o utils.o menu.o terminal.o help.o mqtt.o queue.o - gcc main.o display.o serial.o comunication.o sensor.o lcd.o utils.o menu.o terminal.o help.o mqtt.o queue.o -o Rasp -l paho-mqtt3c + gcc main.o display.o serial.o comunication.o sensor.o lcd.o utils.o menu.o terminal.o help.o mqtt.o queue.o -o Rasp -l paho-mqtt3c -l pthread -Wall Rasp.o: main.c gcc -c main.c -o main.o diff --git a/IHM_Local/mqtt.c b/IHM_Local/mqtt.c index e6955b8..4583861 100644 --- a/IHM_Local/mqtt.c +++ b/IHM_Local/mqtt.c @@ -99,6 +99,11 @@ int on_message(void *context, char *topicName, int topicLen, MQTTClient_message /* Faz echo da mensagem recebida */ //publish(data->client, MQTT_PUBLISH_TOPIC, payload); + + if (strcmp("nwUP", topicName) == 0) { + int nnn = atoi(payload); + *data->update_interval = nnn; + } MQTTClient_freeMessage(&message); //MQTTClient_free(topicName); return 1; diff --git a/IHM_Local/mqtt.h b/IHM_Local/mqtt.h index 1509a73..f8d0313 100644 --- a/IHM_Local/mqtt.h +++ b/IHM_Local/mqtt.h @@ -19,6 +19,7 @@ struct mqtt_context { Sensor *digitals; int *digitalQtd; MQTTClient_connectOptions *MQTT_CONFIG; + int *update_interval; int update_blocked; }; diff --git a/IHM_Local/sensor.c b/IHM_Local/sensor.c index 727cd0f..72505d9 100644 --- a/IHM_Local/sensor.c +++ b/IHM_Local/sensor.c @@ -2,6 +2,8 @@ #include #include // sprintf, printf +void escreverEmDuasLinhas(char linha1[], char linha2[]); + void print_sensor_to_console(char *sensor_name, int sensor_value) { char str[16]; sprintf(str, "%9s: %4i", sensor_name, sensor_value);