-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
samples: adding sample to communicate with aws iot #23469
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.13.1) | ||
|
||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) | ||
project(mqtt-azure) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
CONFIG_NETWORKING=y | ||
|
||
# Disable IPv6 support | ||
CONFIG_NET_IPV6=n | ||
|
||
# Enable IPv4 support | ||
CONFIG_NET_IPV4=y | ||
CONFIG_NET_IF_MAX_IPV4_COUNT=2 | ||
CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT=3 | ||
|
||
# Enable TCP support | ||
CONFIG_NET_TCP=y | ||
|
||
# Enable Sockets support | ||
CONFIG_NET_SOCKETS=y | ||
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y | ||
|
||
# Enable DHCPv4 support | ||
CONFIG_NET_DHCPV4=y | ||
|
||
# Enable SOCKS5 proxy support | ||
CONFIG_SOCKS=n | ||
|
||
# Enable MQTT Lib support | ||
CONFIG_MQTT_LIB=y | ||
CONFIG_MQTT_LIB_TLS=y | ||
|
||
# Network configuration | ||
CONFIG_NET_CONFIG_SETTINGS=y | ||
|
||
# Network connection manager | ||
CONFIG_NET_CONNECTION_MANAGER=y | ||
|
||
CONFIG_NET_MGMT_EVENT_STACK_SIZE=1024 | ||
CONFIG_NET_MGMT_EVENT_QUEUE_SIZE=5 | ||
CONFIG_NET_MGMT_EVENT_LOG_LEVEL_DBG=n | ||
|
||
CONFIG_DNS_RESOLVER=y | ||
CONFIG_DNS_SERVER_IP_ADDRESSES=y | ||
CONFIG_DNS_SERVER1="8.8.8.8" | ||
CONFIG_DNS_RESOLVER_ADDITIONAL_BUF_CTR=2 | ||
CONFIG_NEWLIB_LIBC=y | ||
|
||
CONFIG_INIT_STACKS=y | ||
CONFIG_NET_SHELL=y | ||
|
||
CONFIG_MAIN_STACK_SIZE=4096 | ||
|
||
# Enable Logging support | ||
CONFIG_LOG_IMMEDIATE=y | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the immediate logging, it can slow down the system and is useful only in limited use cases. |
||
CONFIG_NET_LOG=y | ||
CONFIG_MQTT_LOG_LEVEL_DBG=y | ||
CONFIG_SOCKS_LOG_LEVEL_DBG=n | ||
CONFIG_NET_CONNECTION_MANAGER_LOG_LEVEL_DBG=n | ||
CONFIG_DNS_RESOLVER_LOG_LEVEL_DBG=n | ||
CONFIG_NET_CONTEXT_LOG_LEVEL_DBG=n | ||
CONFIG_SOC_PART_NUMBER_SAME70Q21B=y | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove board specific stuff from this file. If you need to enable something board specific, create |
||
CONFIG_SNTP=y | ||
CONFIG_NET_SOCKETS_POSIX_NAMES=y | ||
CONFIG_MAIN_STACK_SIZE=4096 | ||
CONFIG_MQTT_LIB_TLS=y | ||
|
||
# Enable Mbed TLS configuration | ||
CONFIG_MBEDTLS=y | ||
CONFIG_MBEDTLS_BUILTIN=y | ||
CONFIG_MBEDTLS_ENABLE_HEAP=y | ||
CONFIG_MBEDTLS_HEAP_SIZE=100000 | ||
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=10240 | ||
CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y | ||
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED=y |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
sample: | ||
description: MQTT sample app to AWS IoT cloud | ||
name: aws-mqtt | ||
tests: | ||
sample.net.cloud.aws_mqtt: | ||
harness: net | ||
platform_whitelist: sam_e70_xplained | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the whitelisting and put instead minimum ram requirement. That way the sample can be run any device with network connectivity and enough ram. |
||
tags: net mqtt cloud |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* openssl x509 -in <filename>.pem -inform pem -noout -C | ||
*/ | ||
|
||
#error "Fill this before generating the build" | ||
|
||
unsigned char amazon_certificate[] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer that we do things here similar way as in other samples where some file needs to be embedded into the binary. So please write this as
if the cert is in ascii format. If you have the cert in binary format (DER), there is automatic way to create a file that can be included here (search generate_inc_file in networking samples for an example). |
||
}; | ||
|
||
|
||
unsigned char private_key[] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this key expected to be filled in by someone? Please look at the |
||
}; | ||
|
||
unsigned char server_cert[862] = { | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef __CONFIG_H__ | ||
#define __CONFIG_H__ | ||
|
||
#define ALIVE_TIME (MSEC_PER_SEC * 60U) | ||
#define APP_MQTT_BUFFER_SIZE 128 | ||
#error "Fill the Host Name and compile" | ||
#define CONFIG_AWS_HOSTNAME "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hostname must be provided via Kconfig file in this case. A sample app can have a Kconfig file of its own, see other networking samples how to do it. |
||
#define CONFIG_AWS_PORT 8883 | ||
#define MQTT_CLIENTID "zephyr_publisher" | ||
|
||
#endif /* __CONFIG_H__ */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* DHCPv4 client startup. */ | ||
|
||
/* | ||
* Copyright (c) 2018 Linaro Ltd | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <logging/log.h> | ||
|
||
LOG_MODULE_DECLARE(aws_mqtt, LOG_LEVEL_DBG); | ||
|
||
#include <zephyr.h> | ||
|
||
#include <net/net_if.h> | ||
#include <net/net_core.h> | ||
#include <net/net_context.h> | ||
#include <net/net_mgmt.h> | ||
|
||
static struct net_mgmt_event_callback mgmt_cb; | ||
|
||
/* Semaphore to indicate a lease has been acquired. */ | ||
static K_SEM_DEFINE(got_address, 0, 1); | ||
|
||
static void handler(struct net_mgmt_event_callback *cb, | ||
u32_t mgmt_event, | ||
struct net_if *iface) | ||
{ | ||
int i; | ||
bool notified = false; | ||
|
||
if (mgmt_event != NET_EVENT_IPV4_ADDR_ADD) { | ||
return; | ||
} | ||
|
||
for (i = 0; i < NET_IF_MAX_IPV4_ADDR; i++) { | ||
|
||
if (iface->config.ip.ipv4->unicast[i].addr_type != | ||
NET_ADDR_DHCP) { | ||
continue; | ||
} | ||
|
||
if (!notified) { | ||
k_sem_give(&got_address); | ||
notified = true; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* Start a DHCP client, and wait for a lease to be acquired. | ||
*/ | ||
void app_dhcpv4_startup(void) | ||
{ | ||
LOG_INF("starting DHCPv4"); | ||
|
||
net_mgmt_init_event_callback(&mgmt_cb, handler, | ||
NET_EVENT_IPV4_ADDR_ADD); | ||
net_mgmt_add_event_callback(&mgmt_cb); | ||
|
||
net_dhcpv4_start(net_if_get_default()); | ||
|
||
/* Wait for a lease. */ | ||
k_sem_take(&got_address, K_FOREVER); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* DHCPv4 client startup. */ | ||
|
||
/* | ||
* Copyright (c) 2018 Linaro Ltd | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef __DHCP_H__ | ||
#define __DHCP_H__ | ||
|
||
void app_dhcpv4_startup(void); | ||
|
||
#endif /* not __DHCP_H__ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the commit subject to
samples: net: cloud: Add AWS IoT sample
You also need to add something in commit body. In this case it could just be something like
Please also go through style issues that the checkpatch complains about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do i need to push a new commit or create a new pull request, i am unaware about the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just squash your changes together (as you had only 1 commit in this PR) and then force push to this branch related to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to confirm, make all the changes in another commit and push to the branch,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, just squash the changes in the same branch and force push to this PR