push some old updates
This commit is contained in:
parent
042e59d1c6
commit
24ffd1d79a
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "paho.mqtt.c"]
|
||||
path = libs/paho.mqtt.c/
|
||||
url = https://github.com/eclipse/paho.mqtt.c.git
|
||||
14
Makefile
14
Makefile
@ -1,11 +1,19 @@
|
||||
|
||||
SRC := src/main.c src/mqtt.c src/module.c src/modules/*.c
|
||||
INC := -I src -I include/paho-mqtt
|
||||
LIBS := -Llibs/paho-mqtt -lpthread -lpaho-mqtt3a -lpaho-mqtt3c -lpthread
|
||||
INC := -I src
|
||||
LIBS := -lpthread -lpthread
|
||||
|
||||
# paho mqtt
|
||||
LIBPAHO_DIR := libs/paho.mqtt.c
|
||||
INC += -I $(LIBPAHO_DIR)/src
|
||||
LIBS += -L$(LIBPAHO_DIR)/build/output -lpaho-mqtt3a -lpaho-mqtt3c
|
||||
|
||||
all: build
|
||||
|
||||
build: $(SRC)
|
||||
build-paho: $(LIBPAHO_DIR)
|
||||
cd $(LIBPAHO_DIR) && make build
|
||||
|
||||
build: $(SRC) | ${build-paho}
|
||||
gcc $(SRC) $(LIBS) -o mqttClient $(INC)
|
||||
|
||||
debug: $(SRC)
|
||||
|
||||
@ -1 +0,0 @@
|
||||
libpaho-mqtt3a.so.1
|
||||
@ -1 +0,0 @@
|
||||
libpaho-mqtt3a.so.1.3.12
|
||||
Binary file not shown.
@ -1 +0,0 @@
|
||||
libpaho-mqtt3as.so.1
|
||||
@ -1 +0,0 @@
|
||||
libpaho-mqtt3as.so.1.3.12
|
||||
Binary file not shown.
@ -1 +0,0 @@
|
||||
libpaho-mqtt3c.so.1
|
||||
@ -1 +0,0 @@
|
||||
libpaho-mqtt3c.so.1.3.12
|
||||
Binary file not shown.
@ -1 +0,0 @@
|
||||
libpaho-mqtt3cs.so.1
|
||||
@ -1 +0,0 @@
|
||||
libpaho-mqtt3cs.so.1.3.12
|
||||
Binary file not shown.
@ -9,7 +9,7 @@
|
||||
|
||||
void button1(char *topicName, int topicLen, MQTTAsync_message *message)
|
||||
{
|
||||
printf("DEBUG: buttons.button1(): payload = %s", (char*)message->payload);
|
||||
MQTT_publish("/cool/ledkast/set", 1, "{\"status\":\"TOGGLE\"}");
|
||||
}
|
||||
|
||||
void Buttons_Stop()
|
||||
|
||||
@ -63,7 +63,7 @@ void sendTick(char* name, struct tm* t)
|
||||
);
|
||||
printf("topic = %s\n", &topic[0]);
|
||||
|
||||
MQTT_publish(topic, &payload[0], 1);
|
||||
MQTT_publish(topic, 1, &payload[0]);
|
||||
}
|
||||
|
||||
void *Worker(void *args)
|
||||
|
||||
27
src/mqtt.c
27
src/mqtt.c
@ -76,7 +76,7 @@ void MQTT_subscribe(char* topic, int qos, void (*onMessage)(char* topicName, int
|
||||
opts.onSuccess = &onSubscribe;
|
||||
opts.onFailure = &onSubscribeFailure;
|
||||
opts.context = ⊂
|
||||
rc = MQTTAsync_subscribe(Client->client, "#", qos, &opts);
|
||||
rc = MQTTAsync_subscribe(Client->client, sub.topic, qos, &opts);
|
||||
// rc = MQTTAsync_subscribe(Client->client, topic, qos, &opts);
|
||||
|
||||
if (rc != MQTTASYNC_SUCCESS){
|
||||
@ -84,10 +84,11 @@ void MQTT_subscribe(char* topic, int qos, void (*onMessage)(char* topicName, int
|
||||
}
|
||||
}
|
||||
|
||||
void MQTT_publish(char* topic, char* payload, int qos)
|
||||
void MQTT_publish(char* topic, int qos, char* payload)
|
||||
{
|
||||
printf("Publishing to %s", topic);
|
||||
MQTTClient_publish(Client->client, topic, strlen(payload), payload, qos, 0, NULL);
|
||||
printf("Publishing to %s\n", topic);
|
||||
int rc = MQTTClient_publish(Client->client, topic, strlen(payload), payload, qos, 0, NULL);
|
||||
printf("rc = %d\n", rc);
|
||||
}
|
||||
|
||||
int msgarrvd(void *context, char *topicName, int topicLen, MQTTAsync_message *message){
|
||||
@ -95,7 +96,19 @@ int msgarrvd(void *context, char *topicName, int topicLen, MQTTAsync_message *me
|
||||
printf(" topic: %s\n", topicName);
|
||||
printf(" message: %.*s\n", message->payloadlen, (char*)message->payload);
|
||||
|
||||
//(*(Client->onMessage))(topicName, topicLen, message);
|
||||
printf("Subscriptions_len = %d\n", Subscriptions_len);
|
||||
for (int i = 0; i < Subscriptions_len; i++)
|
||||
{
|
||||
Subscription_t sub = *(Subscriptions + i*sizeof(Subscription_t));
|
||||
printf("looking for '%s'; looking at '%s'\n", topicName, sub.topic);
|
||||
int r = strcmp(topicName, sub.topic);
|
||||
if(r == 0){
|
||||
printf("match %d\n", r);
|
||||
(*(sub.onMessage))(topicName, topicLen, message);
|
||||
}
|
||||
else
|
||||
printf("NO match %d\n", r);
|
||||
}
|
||||
|
||||
MQTTAsync_freeMessage(&message);
|
||||
MQTTAsync_free(topicName);
|
||||
@ -126,7 +139,7 @@ void reconnect(){
|
||||
Client->last_reconn.c++;
|
||||
}
|
||||
|
||||
void onConnectFailure(void* context, MQTTAsync_failureData* response){
|
||||
void onConnectFailure(void* context, MQTTAsync_failureData5* response){
|
||||
printf("ERROR: MQTT.onConnectFailure(): Connection failed, rc %d\n", response->code);
|
||||
reconnect();
|
||||
}
|
||||
@ -141,7 +154,7 @@ void connlost(void *context, char *cause){
|
||||
reconnect();
|
||||
}
|
||||
|
||||
void onConn(void* context, MQTTAsync_successData* response){
|
||||
void onConn(void* context, MQTTAsync_successData5* response){
|
||||
printf("INFO: MQTT.onConn(): connected to MQTT server\n");
|
||||
|
||||
Client->last_reconn.c = 0;
|
||||
|
||||
@ -20,6 +20,6 @@ clientConf_t* MQTT_connect(void (*onConnect)(void* context));
|
||||
void MQTT_disconnect();
|
||||
|
||||
void MQTT_subscribe(char* topic, int qos, void (*onMessage)(char* topicName, int topicLen, MQTTAsync_message* message));
|
||||
void MQTT_publish(char* topic, char* payload, int qos);
|
||||
void MQTT_publish(char* topic, int qos, char* payload);
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user