Paho MQTT Embedded C client: Use submodule pointing to upstream repo

Due to code organisation of upstream repo, MQTTClient still needs
copying into our repo.
This commit is contained in:
Angus Gratton 2016-05-28 16:23:13 +10:00
parent 9b21c54fc5
commit 42880fded5
23 changed files with 240 additions and 1828 deletions

View file

@ -1,2 +1,6 @@
PROGRAM=blink
EXTRA_COMPONENTS = extras/mbedtls
include ../../common.mk

View file

@ -8,6 +8,10 @@
#include "task.h"
#include "esp8266.h"
#include "mbedtls/aes.h"
#include "xtensa_ops.h"
#include <string.h>
const int gpio = 2;
/* This task uses the high level GPIO API (esp_gpio.h) to blink an LED.
@ -53,6 +57,32 @@ void blinkenRegisterTask(void *pvParameters)
void user_init(void)
{
uart_set_baud(0, 115200);
xTaskCreate(blinkenTask, (signed char *)"blinkenTask", 256, NULL, 2, NULL);
//xTaskCreate(blinkenRegisterTask, (signed char *)"blinkenRegisterTask", 256, NULL, 2, NULL);
static uint8_t data[1024];
static uint8_t output[1024];
static uint8_t iv[16];
static uint8_t key[256 / 8];
memset(data, 0, sizeof(data));
memset(iv, 0, sizeof(iv));
mbedtls_aes_context ctx;
uint32_t before, after;
RSR(before, CCOUNT)
mbedtls_aes_init(&ctx);
mbedtls_aes_setkey_enc(&ctx, key, 256);
for(int r = 0; r < 10; r++) {
mbedtls_aes_crypt_cbc(&ctx,
MBEDTLS_AES_ENCRYPT,
sizeof(data),
iv,
data,
output);
memcpy(data, output, 1024);
}
RSR(after, CCOUNT);
printf("cycle count %d\n", after - before);
vPortExitCritical();
while(1) {}
}

View file

@ -14,6 +14,8 @@
#include <string.h>
#include <xtensa_ops.h>
#include "FreeRTOS.h"
#include "task.h"
@ -92,6 +94,10 @@ void http_get_task(void *pvParameters)
unsigned char buf[1024];
const char *pers = "ssl_client1";
uint64_t total_delta = 0;
uint32_t delta_count = 0;
uint32_t min_delta = UINT32_MAX;
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_ssl_context ssl;
@ -210,6 +216,9 @@ void http_get_task(void *pvParameters)
*/
printf(" . Performing the SSL/TLS handshake...");
uint32_t before, after;
before = xTaskGetTickCount();
while((ret = mbedtls_ssl_handshake(&ssl)) != 0)
{
if(ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE)
@ -219,6 +228,15 @@ void http_get_task(void *pvParameters)
}
}
after = xTaskGetTickCount();
uint32_t delta = after - before;
total_delta += delta;
delta_count += 1;
if(delta < min_delta) {
min_delta = delta;
}
printf("\n\n**** %d tick handshake - average %d min %d ***\n\n", delta, (uint32_t)(total_delta/delta_count), min_delta);
printf(" ok\n");
/*

View file

@ -1,3 +1,18 @@
/*
MQTT Example Client
Connects to mosquitto test server, publishes to /beat and
subscribes to /esptopic
If using mosquitto, then commands to interact with this example are:
mosquitto_pub -h test.mosquitto.org -t /esptopic -m "Hello!"
mosquitto_sub -h test.mosquitto.org -t /beat
Sample code originally by @baoshi, adapted by Yudi Ludkevich & Angus
Gratton. BSD Licensed.
*/
#include "espressif/esp_common.h"
#include "esp/uart.h"
@ -10,15 +25,13 @@
#include <espressif/esp_sta.h>
#include <espressif/esp_wifi.h>
#include <paho_mqtt_c/MQTTESP8266.h>
#include <paho_mqtt_c/MQTTClient.h>
#include <MQTTClient.h>
#include <semphr.h>
/* You can use http://test.mosquitto.org/ to test mqtt_client instead
* of setting up your own MQTT server */
#define MQTT_HOST ("test.mosquitto.org")
#define MQTT_HOST "test.mosquitto.org"
#define MQTT_PORT 1883
#define MQTT_USER NULL
@ -36,21 +49,21 @@ static void beat_task(void *pvParameters)
while (1) {
vTaskDelayUntil(&xLastWakeTime, 10000 / portTICK_RATE_MS);
printf("beat\r\n");
snprintf(msg, PUB_MSG_LEN, "Beat %d\r\n", count++);
printf(msg);
if (xQueueSend(publish_queue, (void *)msg, 0) == pdFALSE) {
printf("Publish queue overflow.\r\n");
}
}
}
static void topic_received(MessageData *md)
static void topic_received(struct MessageData *md)
{
int i;
MQTTMessage *message = md->message;
printf("Received: ");
for( i = 0; i < md->topic->lenstring.len; ++i)
printf("%c", md->topic->lenstring.data[ i ]);
for( i = 0; i < md->topicName->lenstring.len; ++i)
printf("%c", md->topicName->lenstring.data[ i ]);
printf(" = ");
for( i = 0; i < (int)message->payloadlen; ++i)
@ -86,9 +99,9 @@ static const char * get_my_id(void)
static void mqtt_task(void *pvParameters)
{
int ret = 0;
struct Network network;
MQTTClient client = DefaultClient;
int ret = 0;
Client client;
Network network;
char mqtt_client_id[20];
uint8_t mqtt_buf[100];
uint8_t mqtt_readbuf[100];
@ -111,7 +124,7 @@ static void mqtt_task(void *pvParameters)
continue;
}
printf("done\n\r");
NewMQTTClient(&client, &network, 5000, mqtt_buf, 100,
MQTTClient(&client, &network, 5000, mqtt_buf, 100,
mqtt_readbuf, 100);
data.willFlag = 0;
@ -153,7 +166,7 @@ static void mqtt_task(void *pvParameters)
}
ret = MQTTYield(&client, 1000);
if (ret == DISCONNECTED)
if (ret == FAILURE)
break;
}
printf("Connection dropped, request restart\n\r");