Skip to content

Commit

Permalink
✨ Fiz segmentation fault when changing speed
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSRS committed Dec 16, 2022
1 parent 511b0dd commit 8db869f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
19 changes: 15 additions & 4 deletions IHM_Local/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;


Expand All @@ -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);
/*****************************************************************/

Expand Down
2 changes: 1 addition & 1 deletion IHM_Local/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions IHM_Local/mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions IHM_Local/mqtt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct mqtt_context {
Sensor *digitals;
int *digitalQtd;
MQTTClient_connectOptions *MQTT_CONFIG;
int *update_interval;
int update_blocked;
};

Expand Down
2 changes: 2 additions & 0 deletions IHM_Local/sensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include <lcd.h>
#include <stdio.h> // 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);
Expand Down

0 comments on commit 8db869f

Please sign in to comment.