connect gsensor to mqtt :)

This commit is contained in:
Mats van Reenen 2020-10-29 14:30:13 +01:00
parent e40fb26d23
commit 113f95eab1
2 changed files with 26 additions and 11 deletions

View File

@ -12,9 +12,13 @@
#include <ti/drivers/I2C.h>
#include <ti/drivers/i2c/I2CCC32XX.h>
extern void MQTTPublish(char * topic, char * payload);
#define SPEEDYBOI_ADDR 0x18
#define ACCD_X_MSB 0x03
char mqtt_topic[] = "top_pik";
typedef struct {
enum {Vooruit, Achteruit} richting;
double timestamp;
@ -49,17 +53,19 @@ void * GSensorTask(void *args) {
// publish read into mailbox (defined in mqtt.c)
timer += 0.1;
pakketje pakket;
pakket.richting = (buffer_rcv < 0) ? Achteruit : Vooruit;
pakket.timestamp = timer;
pakket.g = abs(buffer_rcv);
// pakketje pakket;
// pakket.richting = (buffer_rcv < 0) ? Achteruit : Vooruit;
// pakket.timestamp = timer;
// pakket.g = abs(buffer_rcv);
char payload[150];
sprintf(&payload, "handshake (richting: %s; timestamp: %.1f)", (buffer_rcv < 0) ? "Achteruit" : "Vooruit", timer);
MQTTPublish(&mqtt_topic, payload);
// MQTTPublish(pakket);
sleeper = 6000000;
while(sleeper) {
sleeper--;
}
usleep(100000U);
}
return 0;

View File

@ -121,6 +121,7 @@ enum{
struct msgQueue
{
int event;
char* topic;
char* payload;
};
@ -544,6 +545,14 @@ int WifiInit(){
return ret;
}
void MQTTPublish(char * topic, char * payload){
struct msgQueue queueElement;
queueElement.event = APP_MQTT_PUBLISH;
queueElement.topic = topic;
queueElement.payload = payload;
int res = mq_send(appQueue, (const char*)&queueElement, sizeof(struct msgQueue), 0);
}
void MQTTTask(void * args){
int32_t ret;
@ -625,9 +634,9 @@ MQTT_DEMO:
LOG_TRACE("APP_MQTT_PUBLISH\r\n");
MQTT_IF_Publish(mqttClientHandle,
"cc32xx/ToggleLED1",
"LED 1 toggle\r\n",
strlen("LED 1 toggle\r\n"),
queueElement.topic,
queueElement.payload,
strlen(queueElement.payload),
MQTT_QOS_2);
}