Commit 3da366e5 authored by Yongjia Niu's avatar Yongjia Niu
Browse files

Import mbed-iot-connect and connect to mqtt server

parent 4ce52ccf
#ifndef __DEVICES_SETTINGS_H__
#define __DEVICES_SETTINGS_H__
#define ENTRY_EMBEST_CPID "617449FD62B649E7AD1050DB4E95096E"
#define ENTRY_EMBEST_ENV "Avnet"
#define ENTRY_EMBEST_COMPANY_NAME "Embest Tech"
#define EMBEST_STM32L4_KIT_DEBUG_NAME "B-L4S5I-IOT01A(STM32L4+ Discovery kit) Debug 1"
#define EMBEST_STM32L4_KIT_DEBUG_ID "B-L4S5I-IOT01A-DBG1"
#endif
#include "mbed.h"
#include "mbed_trace.h"
#include "NTPClient.h"
#include "IoTConnectCommon.h"
#include "IoTConnectClient.h"
#include "IoTConnectHttpClient.h"
#include "devices_settings.h"
#define TRACE_GROUP "Main"
NetworkInterface* network = NULL;
IoTConnectEntry embest(ENTRY_EMBEST_COMPANY_NAME, ENTRY_EMBEST_CPID, ENTRY_EMBEST_ENV);
IoTConnectDevice* stm32_dev;
IoTConnectClient* client = NULL;
IoTConnectHttpClient* http_client = NULL;
NetworkInterface* connect_network() {
NetworkInterface* net = NULL;
......@@ -65,6 +74,8 @@ int main() {
printf("Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
#endif
stm32_dev = new IoTConnectDevice(EMBEST_STM32L4_KIT_DEBUG_ID, EMBEST_STM32L4_KIT_DEBUG_NAME, &embest);
// Connect to network
network = connect_network();
if (network == NULL) {
......@@ -77,5 +88,28 @@ int main() {
return ret;
}
http_client = new IoTConnectHttpClient(network, stm32_dev);
http_client->init_device_cfg();
client = new IoTConnectClient(network, stm32_dev);
ret = client->connect();
if (ret != 0) {
tr_error("Connect failed, exit");
return -1;
}
ret = client->subscribe(MQTT::QOS0);
if (ret != 0) {
tr_error("Failed to subscribe");
return -1;
}
ret = client->start_main_loop();
if (ret != 0) {
tr_error("Failed to start client thread main loop");
return -1;
}
return 0;
}
\ No newline at end of file
https://xterra2.avnet.com/embest/iotconnect/mbed/mbed-iot-connect.git/#50a4db10dfb43fe0940b4e2b5385093dcd4025f1
......@@ -3,11 +3,14 @@
],
"target_overrides": {
"*": {
"rtos.main-thread-stack-size": 8192,
"nsapi.default-wifi-security": "WPA_WPA2",
"nsapi.default-wifi-ssid": "\"NETGEAR86\"",
"nsapi.default-wifi-password": "\"raspberry\"",
"mbed-trace.enable": 1,
"mbed-trace.max-level": "TRACE_LEVEL_DEBUG",
"mbed-mqtt.max-connections": "5",
"mbed-mqtt.max-packet-size": "2048",
"platform.stdio-baud-rate": 115200,
"platform.stdio-convert-newlines": true
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment