Skip to content

Commit

Permalink
Updated Mbed OS to 5.11.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Osamu Koizumi authored and Osamu Koizumi committed Feb 12, 2019
1 parent d9e7cf9 commit 321d7fe
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 43 deletions.
9 changes: 6 additions & 3 deletions MQTTNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class MQTTNetwork {
public:
MQTTNetwork(NetworkInterface* aNetwork) : network(aNetwork) {
socket = new TLSSocket(aNetwork);
socket = new TLSSocket;
}

~MQTTNetwork() {
Expand All @@ -33,7 +33,10 @@ class MQTTNetwork {
}

int connect(const char* hostname, int port, const char *ssl_ca_pem = NULL,
const char *ssl_cli_pem = NULL, const char *ssl_pk_pem = NULL) {
const char *ssl_cli_pem = NULL, const char *ssl_pk_pem = NULL) {
int ret = socket->open(network);
if(ret < 0)
return ret;
socket->set_root_ca_cert(ssl_ca_pem);
socket->set_client_cert_key(ssl_cli_pem, ssl_pk_pem);
return socket->connect(hostname, port);
Expand All @@ -48,4 +51,4 @@ class MQTTNetwork {
TLSSocket* socket;
};

#endif // _MQTTNETWORK_H_
#endif // _MQTTNETWORK_H_
1 change: 0 additions & 1 deletion TLSSocket.lib

This file was deleted.

1 change: 0 additions & 1 deletion easy-connect.lib

This file was deleted.

21 changes: 13 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#define MQTTCLIENT_QOS1 0
#define MQTTCLIENT_QOS2 0

#include "easy-connect.h"
#include "MQTTNetwork.h"
#include "MQTTmbed.h"
#include "MQTTClient.h"
Expand Down Expand Up @@ -71,12 +70,14 @@ int main(int argc, char* argv[])

const float version = 0.1;

NetworkInterface* network = NULL;

DigitalOut led_red(LED_RED, LED_OFF);
DigitalOut led_green(LED_GREEN, LED_OFF);
DigitalOut led_blue(LED_BLUE, LED_OFF);

NetworkInterface* network = NULL;
MQTTNetwork* mqttNetwork = NULL;
MQTT::Client<MQTTNetwork, Countdown, MQTT_MAX_PACKET_SIZE, MQTT_MAX_CONNECTIONS>* mqttClient = NULL;

printf("Mbed to Google IoT Cloud: version is %.2f\r\n", version);
printf("\r\n");

Expand All @@ -85,16 +86,22 @@ int main(int argc, char* argv[])

printf("Opening network interface...\r\n");
{
network = easy_connect(true); // If true, prints out connection details.
network = NetworkInterface::get_default_instance();
if (!network) {
printf("Unable to open network interface.\r\n");
printf("Error! No network inteface found.\n");
return -1;
}

printf("Connecting to network\n");
nsapi_size_or_error_t ret = network->connect();
if (ret) {
printf("Unable to connect! returned %d\n", ret);
return -1;
}
}
printf("Network interface opened successfully.\r\n");
printf("\r\n");


/* NTP - Get the current time. Required to generate JWT. */
NTPClient ntp(network);
ntp.set_server("time.google.com", 123);
Expand All @@ -111,7 +118,6 @@ int main(int argc, char* argv[])
printf("JWT:\r\n%s\r\n\r\n", password);

/* Establish a network connection. */
MQTTNetwork* mqttNetwork = NULL;
printf("Connecting to host %s:%d ...\r\n", MQTT_SERVER_HOST_NAME, MQTT_SERVER_PORT);
{
mqttNetwork = new MQTTNetwork(network);
Expand Down Expand Up @@ -143,7 +149,6 @@ int main(int argc, char* argv[])
+ GOOGLE_REGION + "/registries/" + GOOGLE_REGISTRY + "/devices/" + GOOGLE_DEVICE_ID;

/* Establish a MQTT connection. */
MQTT::Client<MQTTNetwork, Countdown, MQTT_MAX_PACKET_SIZE, MQTT_MAX_CONNECTIONS>* mqttClient = NULL;
printf("MQTT client is connecting to the service ...\r\n");
{
MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
Expand Down
2 changes: 1 addition & 1 deletion mbed-os.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os/#1e676f6eda27c84f61fa97626b1980b9e410b769
https://github.com/ARMmbed/mbed-os/#a8d1d26fa76a27263cc9a69f65df45e3458517a5
31 changes: 2 additions & 29 deletions mbed_app.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,16 @@
{
"macros": [
"MBEDTLS_SHA1_C=1"
],
"config": {
"main-stack-size": {
"value": 8192
},
"network-interface":{
"help": "options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, WIFI_RTW, MESH_LOWPAN_ND, MESH_THREAD, CELLULAR_ONBOARD",
"value": "ETHERNET"
},
"mesh_radio_type": {
"help": "options are ATMEL, MCR20",
"value": "ATMEL"
},
"esp8266-tx": {
"help": "Pin used as TX (connects to ESP8266 RX)",
"value": "D1"
},
"esp8266-rx": {
"help": "Pin used as RX (connects to ESP8266 TX)",
"value": "D0"
},
"wifi-ssid": {
"value": "\"SSID\""
},
"wifi-password": {
"value": "\"PASSWORD\""
},
"esp8266-debug": {
"value": null
}
},
"target_overrides": {
"*": {
"target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"],
"mbed-mesh-api.6lowpan-nd-channel-page": 0,
"mbed-mesh-api.6lowpan-nd-channel": 12,
"mbed-trace.enable": 0,
"tls-socket.debug-level": 0,
"mbed-trace.enable": null,
"platform.stdio-baud-rate": 115200,
"platform.stdio-convert-newlines": false
},
Expand Down

0 comments on commit 321d7fe

Please sign in to comment.