Date   

ILI9340 Display Example

Muhammad Muh <muhammad.muh83@...>
 

Dear All,

I hope you all are doing well.

I am trying an example in
zephyrproject/zephyr/sample/display/ili9340

The example is building fine with nucleo board
west build -b nucleo_l476rg .

BUT

Please advise on the following error when building with nrf52840 west build -b nrf52840_pca10056 .

FAILED: CMakeFiles/app.dir/src/main.c.obj
ccache /home/muh/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DBUILD_VERSION=zephyr-v2.0.0-1364-gbb3cd11bf192 -DKERNEL -DNRF52840_XXAA -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1 -I/home/muh/zephyrproject/zephyr/kernel/include -I/home/muh/zephyrproject/zephyr/arch/arm/include -I/home/muh/zephyrproject/zephyr/include -I/home/muh/zephyrproject/zephyr/include/drivers -Izephyr/include/generated -I/home/muh/zephyrproject/zephyr/soc/arm/nordic_nrf/nrf52 -I/home/muh/zephyrproject/zephyr/ext/hal/cmsis/Core/Include -I/home/muh/zephyrproject/modules/hal/nordic/nrfx -I/home/muh/zephyrproject/modules/hal/nordic/nrfx/drivers/include -I/home/muh/zephyrproject/modules/hal/nordic/nrfx/mdk -I/home/muh/zephyrproject/modules/hal/nordic/. -isystem /home/muh/zephyrproject/zephyr/lib/libc/minimal/include -isystem /home/muh/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/../lib/gcc/arm-ze
phyr-eabi/8.3.0/include -isystem /home/muh/zephyr-sdk-0.10.3/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/8.3.0/include-fixed -Os -imacros/home/muh/zephyrproject/zephyr/samples/display/ili9340/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -mthumb -mcpu=cortex-m4 -imacros/home/muh/zephyrproject/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=/home/muh/zephyrproject/zephyr/samples/display/ili9340=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/muh/zephyrproject/zephyr=ZEPHYR_BASE -ffunction-sections -fdata-sections -mabi=aapcs -march=armv7e-m -std=c99 -nostdinc -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles/app.dir/src/main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj   -c ../src/main.c
../src/main.c: In function 'main':
../src/main.c:49:27: error: 'DT_INST_0_ILITEK_ILI9340_LABEL' undeclared (first use in this function); did you mean 'DT_INST_0_JEDEC_SPI_NOR_LABEL'?
  dev = device_get_binding(DT_INST_0_ILITEK_ILI9340_LABEL);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           DT_INST_0_JEDEC_SPI_NOR_LABEL
../src/main.c:49:27: note: each undeclared identifier is reported only once for each function it appears in
[4/106] Building C object zephyr/CMake...r/soc/arm/nordic_nrf/nrf52/power.c.obj
ninja: build stopped: subcommand failed.

Regards



Re: hci interface stopped working after few hours #ble #hci #nrf52480 #uart

lairdjm
 

Hi,

I’ve previously done testing with the HCI UART and USB sample apps (in older Zephyr versions) with an nRF52840 and linux PC and always found it to not work well. It would start fine, could scan for devices from bluetoothctl and then it just seemed to screw up every time with command timeouts. Never did much digging into why.

Thanks,

Jamie

 

> Hi All,

>

> I'm facing issues regarding ble's hci interface.

> I'm having nrf52840 module on which i run zephyr's hci_uart app for beacon scanning.

> I have Bluez 5.50 installed on my custom board (imx6ull).

>

> hci0 interface on my device is "UP RUNNING". So, i'm able to scan the beacons. (My application scans beacons after every 10 seconds).

>

> Now, When i have put my device for over night testing, then i have observed that after few hours beacon scanning was stopped.

> And i'm getting "Bluetooth: hci0 command 0x200b tx timeout" prints after every 5-10 seconds on the console, still the hci0 interface status is "UP RUNNING", but not able to scan the beacons.

>

> Sometimes also getting the prints like "Bluetooth: hci0: Frame reassembly failed (-84)".

>

> What could be the reason behind this ?

>

> Thanks,

> Mayank


Zephyr base improvement / improved Zephyr user experience

Rasmussen, Torsten
 
Edited

Hi All,

 

I would like to inform you of a suggested improvement on how Zephyr is used in an application and how to source boilerplate.cmake code.

https://github.com/zephyrproject-rtos/zephyr/pull/23054

 

Today, each application contains:
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)

 

My proposal is to create a Zephyr CMake config package, which allows a user to simply write:

find_package(Zephyr)

in the future.

 

But let me describe some reason for suggesting this change.

 

The existing solution works, and for Linux users, it is very common to use environment variables.

However, this solution also have some drawbacks.

 

One drawback, is that developers working both up-/ and downstream may not be able to always has a single ZEPHYR_BASE, and thus they must still remember to source zephyr-env.sh or run zephyr-env.cmd before working.

 

Second drawback is people using IDEs such as Eclipse or SES, must ensure that ZEPHYR_BASE is correctly set BEFORE launching the IDE.

If only having one Zephyr, that is not a big issue, but having out-of-tree applications depending on different Zephyr versions or working both up- / downstream does make this a bit more annoying.

 

Especially many Windows users are not fond of running a command script prior to launching their IDE.

 

Third drawback, is the fact that ZEPHYR_BASE is not sticky after first CMake invocation, as example, if you try the following:

$ source /tmp/zephyr-1/zephyr/zephyr-env.sh

$ cd <path-to-sample>/hello_world

$ mkdir build; cd build

$ cmake -GNinja -DBOARD=nrf52840_pca10056 ..

-- Zephyr version: 2.2.0-rc2

-- Found PythonInterp: /usr/bin/python3.6 (found suitable version "3.6.8", minimum required is "3.6")

Loaded configuration '/tmp/zephyr-1/zephyr/boards/arm/nrf52840_pca10056/nrf52840_pca10056_defconfig'

-- Build files have been written to: /tmp/zephyr-1/zephyr/samples/hello_world/build

$ ninja

[122/122] Linking C executable zephyr/zephyr.elf

 

# This could be similar to a user changing folder to do something else,

# or working in an IDE where the ZEPHYR_BASE is different from the value on first CMake invocation.

# and therefore has sourced a different Zephyr

$ source /tmp/zephyr-2/zephyr/zephyr-env.sh

# Indicate a CMakeLists.txt change causing CMake re-run on next ninja invocation.

$ touch ../CMakeLists.txt

$ ninja

[0/1] Re-running CMake...

-- Zephyr version: 2.1.99

-- Selected BOARD nrf52840_pca10056

-- Found west: /home/<user>/.local/bin/west (found suitable version "0.7.0", minimum required is "0.6.0")

-- Loading /tmp/zephyr-1/zephyr/boards/arm/nrf52840_pca10056/nrf52840_pca10056.dts as base

Error: nrf52840_pca10056.dts.pre.tmp:394.23-24 syntax error

FATAL ERROR: Unable to parse input tree

CMake Error at /tmp/zephyr-2/zephyr/cmake/dts.cmake:188 (message):

  command failed with return code: 1

Call Stack (most recent call first):

  /tmp/zephyr-2/zephyr/cmake/app/boilerplate.cmake:460 (include)

  CMakeLists.txt:5 (include)

 

-- Configuring incomplete, errors occurred!

See also "/tmp/zephyr-1/zephyr/samples/hello_world/build/CMakeFiles/CMakeOutput.log".

See also "/tmp/zephyr-1/zephyr/samples/hello_world/build/CMakeFiles/CMakeError.log".

FAILED: build.ninja

/opt/cmake-3.14.4-Linux-x86_64/bin/cmake -S/tmp/zephyr-1/zephyr/samples/hello_world -B/tmp/zephyr-1/zephyr/samples/hello_world/build

ninja: error: rebuilding 'build.ninja': subcommand failed

$

As seen above, the Zephyr in used is now in mixed state and thus failing.

 

I have therefore made the following PR, which solve both above mentioned problems, as well as give a better user experience.

https://github.com/zephyrproject-rtos/zephyr/pull/23054

It has the following advantages:

  1. CMake will use `find_package` to locate the right Zephyr
  2. Version can be used in an application to ensure the correct Zephyr version for Zephyr users when having multiple Out-of-tree apps
  3. ZEPHYR_BASE is sticky after first CMake invocation, thus if Zephyr based is changed after first run, it will not impact subsequent CMake invocations (directly or through ninja).
  4. Allows to have multiple projects with different Zephyr bases in same IDE, as example Eclipse.
  5. Easier getting started for developers. No boilerplate sourcing, no ZEPHYR_BASE / zephyr-env.sh sourcing, just put:
  6. Fully backward compatible with existing ZEPHYR_BASE.

 

 

So a Zephyr sample such as Hello World may look as:

https://github.com/zephyrproject-rtos/zephyr/blob/a886b9ae428c066bad73cc509757571b70a52d1f/samples/hello_world/CMakeLists.txt
# SPDX-License-Identifier: Apache-2.0

 

cmake_minimum_required(VERSION 3.13.1)

 

find_package(Zephyr 2.2.0 HINTS $ENV{ZEPHYR_BASE})

project(hello_world)

 

target_sources(app PRIVATE src/main.c)

 

 

And a downstream user creating an app based upon Zephyr without version check, can simply do:

`find_package(Zephyr)`

 

If a user wants to support the possibility of overriding the Zephyr by manually specifying ZEPHYR_BASE, the following can be used:  

`find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})`

 

A user requiring Zephyr version 2.2.0 or above can do:

`find_package(Zephyr 2.2.0)`

 

A user requiring an exact Zephyr version 2.2.0 can do:

`find_package(Zephyr 2.2.0 EXACT)`

 

 

To show that Zephyr base is now sticky, I have re-tried above failure using the new principle:

$ source /tmp/zephyr-1/zephyr/zephyr-env.sh

$ mkdir build; cd build

$ cmake -GNinja -DBOARD=nrf52840_pca10056 ..

Including boilerplate (zephyr base): /tmp/zephyr-1/zephyr/cmake/app/boilerplate.cmake

-- Zephyr version: 2.2.0-rc2

-- Found PythonInterp: /usr/bin/python3.6 (found suitable version "3.6.8", minimum required is "3.6")

Loaded configuration '/tmp/zephyr-1/zephyr/boards/arm/nrf52840_pca10056/nrf52840_pca10056_defconfig'

-- Build files have been written to: /tmp/zephyr-1/zephyr/samples/hello_world/build

$ ninja

[119/124] Linking C executable zephyr/zephyr_prebuilt.elf

Memory region         Used Size  Region Size  %age Used

           FLASH:       11484 B         1 MB      1.10%

            SRAM:        5180 B       256 KB      1.98%

        IDT_LIST:          56 B         2 KB      2.73%

[124/124] Linking C executable zephyr/zephyr.elf

 

$ source /tmp/zephyr-2/zephyr/zephyr-env.sh

$ touch ../CMakeLists.txt

$ ninja

[0/1] Re-running CMake...

Including boilerplate (zephyr base (cached)): /tmp/zephyr-1/zephyr/cmake/app/boilerplate.cmake

-- Zephyr version: 2.2.0-rc2

-- Loading /tmp/zephyr-1/zephyr/boards/arm/nrf52840_pca10056/nrf52840_pca10056.dts as base

Loaded configuration '/tmp/zephyr-1/zephyr/samples/hello_world/build/zephyr/.config'

No change to configuration in '/tmp/zephyr-1/zephyr/samples/hello_world/build/zephyr/.config'

No change to Kconfig header in '/tmp/zephyr-1/zephyr/samples/hello_world/build/zephyr/include/generated/autoconf.h'

-- Build files have been written to: /tmp/zephyr-1/zephyr/samples/hello_world/build

[86/90] Linking C executable zephyr/zephyr_prebuilt.elf

[90/90] Linking C executable zephyr/zephyr.elf

$ echo $ZEPHYR_BASE

/tmp/zephyr-2/zephyr

 

Also a small screenshot from Eclipse to show that two projects can be imported with different Zephyr bases, and both be built and using their own Zephyr base (and in  this example own requested Zephyr version):

 

 

If anyone is interested in a presentation of the new possibilities, I will be happy to make a small presentation for next TSC meeting.

 

 

Torsten Tejlmand Rasmussen

Senior R&D Engineer

P: +47 72 89 92 47

 

Nordic

 

Nordic Semiconductor

Otto Nielsens veg 12, 7052 Trondheim, Norway

www.nordicsemi.com

 

 

SM_symbol_FB  nordic_symbol_small_TW  nordic_symbol_small_YT_ny2  nordic_symbol_small_IN  

 

DevZone

           

 


hci interface stopped working after few hours #ble #hci #nrf52480 #uart

Mayank
 

Hi All,

I'm facing issues regarding ble's hci interface.
I'm having nrf52840 module on which i run zephyr's hci_uart app for beacon scanning.
I have Bluez 5.50 installed on my custom board (imx6ull).

hci0 interface on my device is "UP RUNNING". So, i'm able to scan the beacons. (My application scans beacons after every 10 seconds).

Now, When i have put my device for over night testing, then i have observed that after few hours beacon scanning was stopped.
And i'm getting "Bluetooth: hci0 command 0x200b tx timeout" prints after every 5-10 seconds on the console, still the hci0 interface status is "UP RUNNING", but not able to scan the beacons.

Sometimes also getting the prints like "Bluetooth: hci0: Frame reassembly failed (-84)".

What could be the reason behind this ?

Thanks,
Mayank


API meeting next week: Focusing on watchdogs

Carles Cufi
 

Hi all,

Next week (Tuesday 10th of March) we will focus our attention to watchdog handling in Zephyr.

We recently closed #22858 with the merge of #22859, but this was a temporary solution to what is ultimately a wider problem that requires a discussion regarding the way Zephyr manages watchdogs in general.

A good description of the current issues with the CONFIG_WDT_DISABLE_AT_BOOT option can be found in #22858.

During the call we will discuss the approach we want to take and document it in #23282, which I just created today.

Original issue:
https://github.com/zephyrproject-rtos/zephyr/issues/22858
Pull request:
https://github.com/zephyrproject-rtos/zephyr/pull/22859
New tracking issue:
https://github.com/zephyrproject-rtos/zephyr/issues/23282

Meeting:
https://github.com/zephyrproject-rtos/zephyr/wiki/Zephyr-Committee-and-Working-Group-Meetings#zephyr-api-discussion

Thanks,

Carles


Re: nrf52840 hang without errors #ble #nrf52840 #uart

Chettimada, Vinayak Kariappa
 

Hi Narendar,

 

Please create a github bug report, with details on how to build your application and reproduce the issue.

You may share a branch in the GH issue if that is faster for me or others  to reproduce and debug.

 

Regards,

Vinayak

 

From: devel@... <devel@...> On Behalf Of Narendar Malepu via Lists.Zephyrproject.Org
Sent: 04 March 2020 08:03
To: devel@...
Cc: devel@...
Subject: [Zephyr-devel] nrf52840 hang without errors #ble #nrf52840 #uart

 

Hi,

 

Iam using nrf52840 development board, developing software using zephyr.

In software development iam using bluetooth as a peripheral and uart in interrupt mode(to get data from other module), when iam trying to run both interfaces the board is getting hang without any errors and iam included watchdog timer so after sometime it is restarting.

When iam trying same fuctionality without using interrupt for uart and bluetooth, after some time device is stopping advertisments but uart is working fine.

can someone help me with above problem.

 

Thanks.


nrf52840 hang without errors #ble #nrf52840 #uart

Narendar Malepu
 

Hi,

 

Iam using nrf52840 development board, developing software using zephyr.

In software development iam using bluetooth as a peripheral and uart in interrupt mode(to get data from other module), when iam trying to run both interfaces the board is getting hang without any errors and iam included watchdog timer so after sometime it is restarting.

When iam trying same fuctionality without using interrupt for uart and bluetooth, after some time device is stopping advertisments but uart is working fine.

can someone help me with above problem.

 

Thanks.


Re: To bring back RPL to Zephyr project

Tomasz Bursztyka
 

Hi,

Former RPL was a port of contiki's RPL implementation, if I am not
mistaken. But it slipped a lot compared to its original code, which one
got a lot more features implemented.

Also, the issue with it, was that it was not very well following our
common design scheme in the network stack, since that was a code from
another OS. It was quite messy, and not optimized as well (a lot of
timers everywher, the context data for RPL was way too big). I'd advise
to reimplement RPL support from scratch. It should be simpler as well
now that net_pkt got its API reworked. Following the design in
ipv6_nbr.c would be a good example I guess.

Br,

Tomasz

Hi,

I would also be interested in getting RPL back. Do you already have a
branch somewhere? I would also be willing to participate in the
porting.

Best Regards,

Max


Upcoming Event: Zephyr Project: APIs - Tue, 03/03/2020 9:00am-10:00am, Please RSVP #cal-reminder

devel@lists.zephyrproject.org Calendar <devel@...>
 

Reminder: Zephyr Project: APIs

When: Tuesday, 3 March 2020, 9:00am to 10:00am, (GMT-08:00) America/Los Angeles

Where:https://zoom.us/j/177647878

An RSVP is requested. Click here to RSVP

Organizer: devel@...

Description: Join from PC, Mac, Linux, iOS or Android: https://zoom.us/j/177647878

Or iPhone one-tap :
    US: +16465588656,,177647878# or +16699006833,,177647878# 
Or Telephone:
    Dial(for higher quality, dial a number based on your current location): 
        US: +1 646 558 8656 or +1 669 900 6833 or +1 855 880 1246 (Toll Free) or +1 877 369 0926 (Toll Free)
    Meeting ID: 177 647 878
    International numbers available: https://zoom.us/zoomconference?m=ioAR9GK1OE5LkN1ojt-heTCl7yPcJrhY


 Live meeting minutes: https://docs.google.com/document/d/1lv-8B5QE2m4FjBcvfqAXFIgQfW5oz6306zJ7GIZIWCk/edit?usp=sharing


Re: To bring back RPL to Zephyr project

Schuh Max
 

Hi,

I would also be interested in getting RPL back. Do you already have a branch somewhere? I would also be willing to participate in the porting.

Best Regards,

Max


API meeting: agenda

Carles Cufi
 

Hi all,

The topics for today:

- PR: Fix handling of WDT_DISABLE_AT_BOOT option
- https://github.com/zephyrproject-rtos/zephyr/pull/22859

- PR (cont): generalize async notification and add queued operation manager
- https://github.com/zephyrproject-rtos/zephyr/pull/22853

- PR (RFC): asynchronous sequence manager (assuming the relevant stakeholders are present)
- https://github.com/zephyrproject-rtos/zephyr/pull/23075

Additional items in the "Triage" column in the GitHub project may be discussed if time permits.
If you want an item included in the meeting, please add it to the GitHub project.

https://github.com/zephyrproject-rtos/zephyr/wiki/Zephyr-Committee-and-Working-Group-Meetings#zephyr-api-discussion
https://github.com/zephyrproject-rtos/zephyr/projects/18
https://docs.google.com/document/d/1lv-8B5QE2m4FjBcvfqAXFIgQfW5oz6306zJ7GIZIWCk/edit

Regards,

Carles


Re: CONFIG_MBEDTLS_BUILTIN vs CONFIG_MBEDTLS_LIBRARY

Paul Sokolovsky
 

Hello,

On Mon, 2 Mar 2020 14:15:57 +0000
"Sebastian Boe" <Sebastian.Boe@...> wrote:

Hi,

I would recommend opening menuconfig and reading the help text for
each option.
It's also possible to search/read config option descriptions in Zephyr
docs, just go to https://docs.zephyrproject.org/latest/ , paste an
option name into search field on the left, and voila.

That said, in this case, option descriptions are rather bare and hardly
can be understood without knowing more context (like, being a Zephyr
developer with some experience):
https://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_MBEDTLS_LIBRARY.html

I'd suggest we use questions like this to actually improve config
option descriptions. In that regard, I submitted
https://github.com/zephyrproject-rtos/zephyr/pull/23217


Subject: [Zephyr-devel] CONFIG_MBEDTLS_BUILTIN vs
CONFIG_MBEDTLS_LIBRARY

Hi All,

What is the difference between CONFIG_MBEDTLS_BUILTIN vs
CONFIG_MBEDTLS_LIBRARY

When i set CONFIG_MBEDTLS_LIBRARY it is throwing error:

/home/jamal/zephyrproject/zephyr/subsys/net/lib/sockets/sockets_tls.c:24:10:
fatal error: mbedtls/config.h: No such file or directory #include
"mbedtls/config.h" ^~~~~~~~~~~~~~~~~~
compilation terminated.

I want to set MBEDTLS_X509_CRT_PARSE_C, so that my certificate and
private keys are parsed by the mbedtls library, can you please
provide me steps to achieve this?
--
Best Regards,
Paul

Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog


Re: Why is TLS_CREDENTIAL_PRIVATE_KEY not implemented

Lubos, Robert
 

I’m afraid you’ve misunderstood the code in there. Just by the fact the `case TLS_CREDENTIAL_PRIVATE_KEY` is empty does not mean that private key management is not implemented (which is more or less explained in the comment).

 

As private key needs to be registered together with its corresponding public certificate, they’re handled together in the condition above. That’s why there’s no need for an action, when private key is encountered:

https://github.com/zephyrproject-rtos/zephyr/blob/master/subsys/net/lib/sockets/sockets_tls.c#L672

 

This mechanism is for instance used in `echo_server` sample, where both private key and server certificate are registered, and later on used in the sample:

https://github.com/zephyrproject-rtos/zephyr/blob/master/samples/net/sockets/echo_server/src/echo-server.c#L63

 

Regards,

Robert

 

From: devel@... [mailto:devel@...] On Behalf Of Linux Weekend Learning via Lists.Zephyrproject.Org
Sent: Monday, March 2, 2020 17:19
To: devel@...
Cc: devel@...
Subject: [Zephyr-devel] Why is TLS_CREDENTIAL_PRIVATE_KEY not implemented

 

I tried to debug my problem and found that  TLS_CREDENTIAL_PRIVATE_KEY is not implemented. I need to set private key and my certificate and both are not implemented. When setting

certificate it is looking for private key which is not stored

This is the code in socket_tls.c file tls_set_credential

 

 case TLS_CREDENTIAL_PRIVATE_KEY:
/* Ignore private key - it will be used together
* with public certificate
*/
break;


Why is TLS_CREDENTIAL_PRIVATE_KEY not implemented

Linux Weekend Learning
 

I tried to debug my problem and found that  TLS_CREDENTIAL_PRIVATE_KEY is not implemented. I need to set private key and my certificate and both are not implemented. When setting
certificate it is looking for private key which is not stored
This is the code in socket_tls.c file tls_set_credential

 case TLS_CREDENTIAL_PRIVATE_KEY:
/* Ignore private key - it will be used together
* with public certificate
*/
break;


Re: CONFIG_MBEDTLS_BUILTIN vs CONFIG_MBEDTLS_LIBRARY

Linux Weekend Learning
 

I added this in my prj.conf file

CONFIG_MBEDTLS_USER_CONFIG_ENABLE=y
CONFIG_MBEDTLS_USER_CONFIG_FILE="user-tls.conf"

user-tls.conf file:

#define MBEDTLS_X509_CRT_PARSE_C

In my code, i added a check to see whether this is enabled or not
#if defined(MBEDTLS_X509_CRT_PARSE_C)
LOG_INF("Enabled");
#endif

This log is not printing, what mistake i am doing. i need to set  MBEDTLS_X509_CRT_PARSE_C for certificate and private key to be accepted by socket_tls.c


On Mon, Mar 2, 2020 at 7:45 PM Bøe, Sebastian <Sebastian.Boe@...> wrote:
Hi,

I would recommend opening menuconfig and reading the help text for each option.

________________________________________
From: devel@... <devel@...> on behalf of Linux Weekend Learning via Lists.Zephyrproject.Org <md.jamalmohiuddin=gmail.com@...>
Sent: Monday, March 2, 2020 3:14 PM
To: devel@...
Cc: devel@...
Subject: [Zephyr-devel] CONFIG_MBEDTLS_BUILTIN vs CONFIG_MBEDTLS_LIBRARY

Hi All,

What is the difference between CONFIG_MBEDTLS_BUILTIN vs  CONFIG_MBEDTLS_LIBRARY

When i set  CONFIG_MBEDTLS_LIBRARY it is throwing error:

/home/jamal/zephyrproject/zephyr/subsys/net/lib/sockets/sockets_tls.c:24:10: fatal error: mbedtls/config.h: No such file or directory
 #include "mbedtls/config.h"
          ^~~~~~~~~~~~~~~~~~
compilation terminated.

I want to set MBEDTLS_X509_CRT_PARSE_C, so that my certificate and private keys are parsed by the mbedtls library, can you please provide me steps to achieve this?


Re: CONFIG_MBEDTLS_BUILTIN vs CONFIG_MBEDTLS_LIBRARY

Sebastian Boe
 

Hi,

I would recommend opening menuconfig and reading the help text for each option.

________________________________________
From: devel@... <devel@...> on behalf of Linux Weekend Learning via Lists.Zephyrproject.Org <md.jamalmohiuddin=gmail.com@...>
Sent: Monday, March 2, 2020 3:14 PM
To: devel@...
Cc: devel@...
Subject: [Zephyr-devel] CONFIG_MBEDTLS_BUILTIN vs CONFIG_MBEDTLS_LIBRARY

Hi All,

What is the difference between CONFIG_MBEDTLS_BUILTIN vs CONFIG_MBEDTLS_LIBRARY

When i set CONFIG_MBEDTLS_LIBRARY it is throwing error:

/home/jamal/zephyrproject/zephyr/subsys/net/lib/sockets/sockets_tls.c:24:10: fatal error: mbedtls/config.h: No such file or directory
#include "mbedtls/config.h"
^~~~~~~~~~~~~~~~~~
compilation terminated.

I want to set MBEDTLS_X509_CRT_PARSE_C, so that my certificate and private keys are parsed by the mbedtls library, can you please provide me steps to achieve this?


CONFIG_MBEDTLS_BUILTIN vs CONFIG_MBEDTLS_LIBRARY

Linux Weekend Learning
 

Hi All,

What is the difference between CONFIG_MBEDTLS_BUILTIN vs  CONFIG_MBEDTLS_LIBRARY

When i set  CONFIG_MBEDTLS_LIBRARY it is throwing error:

/home/jamal/zephyrproject/zephyr/subsys/net/lib/sockets/sockets_tls.c:24:10: fatal error: mbedtls/config.h: No such file or directory
 #include "mbedtls/config.h"
          ^~~~~~~~~~~~~~~~~~
compilation terminated.

I want to set MBEDTLS_X509_CRT_PARSE_C, so that my certificate and private keys are parsed by the mbedtls library, can you please provide me steps to achieve this?


Re: mqtt_connect blocked at connect stage

Jukka Rissanen
 

Hi,

some comments inline below:

On Sun, 2020-03-01 at 10:01 +0530, Linux Weekend Learning wrote:

static void broker_init(void)
{
struct sockaddr_in *broker4 = (struct sockaddr_in *)&broker;

broker4->sin_family = AF_INET;
broker4->sin_port = htons(8883);

net_ipaddr_copy(&broker4->sin_addr,
&net_sin(haddr->ai_addr)->sin_addr);

#if defined(CONFIG_SOCKS)
struct sockaddr_in *proxy4 = (struct sockaddr_in *)&socks5_proxy;

proxy4->sin_family = AF_INET;
proxy4->sin_port = htons(1081);
inet_pton(AF_INET, "agwgaprlb6xdl-ats.iot.us-west-2.amazonaws.com",
&proxy4->sin_addr);
Use IP address here instead of hostname.


#endif
}

void mqtt_evt_handler(struct mqtt_client *const client,
const struct mqtt_evt *evt)
{
int err;

switch (evt->type) {
case MQTT_EVT_CONNACK:
if (evt->result != 0) {
LOG_ERR("MQTT connect failed %d", evt->result);
break;
}

connected = true;
LOG_INF("MQTT client connected!");

break;

case MQTT_EVT_DISCONNECT:
LOG_INF("MQTT client disconnected %d", evt->result);

connected = false;
clear_fds();

break;

case MQTT_EVT_PUBACK:
if (evt->result != 0) {
LOG_ERR("MQTT PUBACK error %d", evt->result);
break;
}

LOG_INF("PUBACK packet id: %u", evt->param.puback.message_id);

break;

case MQTT_EVT_PUBREC:
if (evt->result != 0) {
LOG_ERR("MQTT PUBREC error %d", evt->result);
break;
}

LOG_INF("PUBREC packet id: %u", evt->param.pubrec.message_id);

const struct mqtt_pubrel_param rel_param = {
.message_id = evt->param.pubrec.message_id
};
err = mqtt_publish_qos2_release(client, &rel_param);
if (err != 0) {
LOG_ERR("Failed to send MQTT PUBREL: %d", err);
}

break;

case MQTT_EVT_PUBCOMP:
if (evt->result != 0) {
LOG_ERR("MQTT PUBCOMP error %d", evt->result);
break;
}

LOG_INF("PUBCOMP packet id: %u",
evt->param.pubcomp.message_id);

break;

default:
break;
}
}


static void client_init(struct mqtt_client *client)
{
static struct mqtt_utf8 password;
static struct mqtt_utf8 username;

mqtt_client_init(client);
broker_init();


password.utf8 = (u8_t *)CONFIG_SAMPLE_CLOUD_AWS_PASSWORD;
password.size = strlen(CONFIG_SAMPLE_CLOUD_AWS_PASSWORD);

client->password = &password;

username.utf8 = (u8_t *)CONFIG_SAMPLE_CLOUD_AWS_USERNAME;
username.size = strlen(CONFIG_SAMPLE_CLOUD_AWS_USERNAME);

client->user_name = &username;


/* MQTT client configuration */
client->broker = &broker;
client->evt_cb = mqtt_evt_handler;
client->client_id.utf8 = (u8_t *)MQTT_CLIENTID;
client->client_id.size = strlen(MQTT_CLIENTID);
client->password = NULL;
client->user_name = NULL;
client->protocol_version = MQTT_VERSION_3_1_1;

/* MQTT buffers configuration */
client->rx_buf = rx_buffer;
client->rx_buf_size = sizeof(rx_buffer);
client->tx_buf = tx_buffer;
client->tx_buf_size = sizeof(tx_buffer);

client->transport.type = MQTT_TRANSPORT_SECURE;

struct mqtt_sec_config *tls_config = &client->transport.tls.config;

tls_config->peer_verify = TLS_PEER_VERIFY_REQUIRED;
tls_config->cipher_list = NULL;
tls_config->sec_tag_list = m_sec_tags;
tls_config->sec_tag_count = ARRAY_SIZE(m_sec_tags);
tls_config->hostname = "agwgaprlb6xdl-ats.iot.us-west-
2.amazonaws.com";
client->transport.type = MQTT_TRANSPORT_SECURE;
#if defined(CONFIG_SOCKS)
mqtt_client_set_proxy(client, &socks5_proxy,
socks5_proxy.sa_family == AF_INET ?
sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6));
#endif


}
#define RC_STR(rc) ((rc) == 0 ? "OK" : "ERROR")
#define PRINT_RESULT(func, rc) \
LOG_INF("%s: %d <%s>", (func), rc, RC_STR(rc))
static void prepare_fds(struct mqtt_client *client)
{
if (client->transport.type == MQTT_TRANSPORT_NON_SECURE) {
fds[0].fd = client->transport.tcp.sock;
}
#if defined(CONFIG_MQTT_LIB_TLS)
else if (client->transport.type == MQTT_TRANSPORT_SECURE) {
fds[0].fd = client->transport.tls.sock;
}
#endif

fds[0].events = ZSOCK_POLLIN;
nfds = 1;
}

static void wait(int timeout)
{
if (nfds > 0) {
if (poll(fds, nfds, timeout) < 0) {
LOG_ERR("poll error: %d", errno);
}
}
}



static int try_to_connect(struct mqtt_client *client)
{
u8_t retries = 3U;
int rc;

LOG_DBG("attempting to connect...");
You could print the IP address you are trying to connect in order to
verify that it is set correctly.


client_init(client);
rc = mqtt_connect(client);
if (rc != 0) {
PRINT_RESULT("mqtt_connect", rc);
k_sleep(500);
} else {

prepare_fds(client);

wait(500);
mqtt_input(client);
if (!connected) {
LOG_INF("Aborting connection\n");
mqtt_abort(client);
}

}
if (connected) {
return 0;
}

return -EINVAL;

}


static int tls_init(void)
{
int err = -EINVAL;
LOG_INF("Ca size:%d\n", sizeof(ca_certificate));
err = tls_credential_add(APP_CA_CERT_TAG,
TLS_CREDENTIAL_CA_CERTIFICATE,
ca_certificate,
sizeof(ca_certificate));
if (err < 0) {
LOG_ERR("Failed to register public certificate: %d",
err);
return err;
}


return err;
}


void mqtt_startup(char *hostname, int port)
{
struct mqtt_client *client = &client_ctx;
int retries = 5;
int err, cnt;
static struct zsock_addrinfo hints;
int res = 0;
int rc;




hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
cnt = 0;
while ((err = getaddrinfo("agwgaprlb6xdl-ats.iot.us-west-
2.amazonaws.com", "8883", &hints,
&haddr)) && cnt < 3) {
LOG_ERR("Unable to get address for broker, retrying");
cnt++;
}
if (err != 0) {
LOG_ERR("Unable to get address for broker, error %d",
res);
return;
}
LOG_INF("DNS resolved for agwgaprlb6xdl-ats.iot.us-west-
2.amazonaws.com:8833");
try_to_connect(client);
PRINT_RESULT("try_to_connect", rc);




}

static void show_addrinfo(struct addrinfo *addr)
{
char hr_addr[NET_IPV6_ADDR_LEN];
void *a;

top:
LOG_DBG(" flags : %d", addr->ai_flags);
LOG_DBG(" family : %d", addr->ai_family);
LOG_DBG(" socktype: %d", addr->ai_socktype);
LOG_DBG(" protocol: %d", addr->ai_protocol);
LOG_DBG(" addrlen : %d", (int)addr->ai_addrlen);

/* Assume two words. */
LOG_DBG(" addr[0]: 0x%lx", ((uint32_t *)addr->ai_addr)[0]);
LOG_DBG(" addr[1]: 0x%lx", ((uint32_t *)addr->ai_addr)[1]);

if (addr->ai_next != 0) {
addr = addr->ai_next;
goto top;
}

a = &net_sin(addr->ai_addr)->sin_addr;
LOG_INF(" Got %s",
log_strdup(net_addr_ntop(addr->ai_family, a,
hr_addr, sizeof(hr_addr))));

}

void do_sntp(struct addrinfo *addr)
{
struct sntp_ctx ctx;
int rc;
s64_t stamp;
struct sntp_time sntp_time;
char time_str[sizeof("1970-01-01T00:00:00")];

LOG_INF("Sending NTP request for current time:");

/* Initialize sntp */
rc = sntp_init(&ctx, addr->ai_addr, sizeof(struct sockaddr_in));
if (rc < 0) {
LOG_ERR("Unable to init sntp context: %d", rc);
return;
}
rc = sntp_query(&ctx, K_FOREVER, &sntp_time);
if (rc == 0) {
stamp = k_uptime_get();
time_base = sntp_time.seconds * MSEC_PER_SEC - stamp;

/* Convert time to make sure. */
time_t now = sntp_time.seconds;
struct tm now_tm;

gmtime_r(&now, &now_tm);
strftime(time_str, sizeof(time_str), "%FT%T", &now_tm);
LOG_INF(" Acquired time: %s", log_strdup(time_str));

} else {
LOG_ERR(" Failed to acquire SNTP, code %d\n", rc);
}

sntp_close(&ctx);
}


void main(void)
{
static struct addrinfo hints;
struct addrinfo *haddr;
int res;
int cnt = 0;
int rc;


app_dhcpv4_startup();

LOG_INF("Should have DHCPv4 lease at this point.");
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = 0;
//while ((res = getaddrinfo("console.aws.amazon.com", "80", &hints,
while ((res = getaddrinfo("time.google.com", "123", &hints,
&haddr)) && cnt < 3) {
LOG_ERR("Unable to get address for NTP server, retrying");
cnt++;
}

if (res != 0) {
LOG_ERR("Unable to get address of NTP server, exiting %d", res);
return;
}


LOG_INF("DNS resolved for console.aws.amazon.com:80");
show_addrinfo(haddr);
do_sntp(haddr);

#if defined(CONFIG_MQTT_LIB_TLS)

rc = tls_init();
PRINT_RESULT("tls_init", rc);
#endif

mqtt_startup("agwgaprlb6xdl-ats.iot.us-west-2.amazonaws.com", 8883);

}

Console Logs:

[00:00:09.666,000] <inf> aws_mqtt: tls_init: 0 <OK>
[00:00:09.706,000] <inf> aws_mqtt: DNS resolved for agwgaprlb6xdl-
ats.iot.us-west-2.amazonaws.com:8833
[00:00:09.718,000] <dbg> aws_mqtt.try_to_connect: attempting to
connect...
[00:00:09.727,000] <dbg> net_mqtt_sock_tls.mqtt_client_tls_connect:
(0x20401bac): Created socket 0
[00:00:09.739,000] <dbg> net_mqtt_sock_tls.mqtt_client_tls_connect:
(0x20401bac): Before Connect completed
_._,_._,_

Cheers,
Jukka


mqtt_connect blocked at connect stage

Linux Weekend Learning
 

Hi Guys,

Please help me out here, the code is blocked internally when calling 'connect'

I wrote a code to connect to the Amazon Web Services IOT Service

/*
 * Copyright (c) 2019 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <logging/log.h>
LOG_MODULE_REGISTER(aws_mqtt, LOG_LEVEL_DBG);

#include <zephyr.h>
#include <net/socket.h>
#include <net/mqtt.h>
#include <net/net_config.h>
#include <net/net_event.h>
#include <net/sntp.h>

#include <sys/printk.h>
#include <string.h>
#include <errno.h>
#include "dhcp.h"
#include <time.h>
#include <inttypes.h>
#include "test_certs.h"
#if defined(CONFIG_SOCKS)
static struct sockaddr socks5_proxy;
#endif
static struct pollfd fds[1];
static int nfds;

#define CONFIG_SAMPLE_CLOUD_AWS_PASSWORD ""
#define CONFIG_SAMPLE_CLOUD_AWS_USERNAME ""

#define APP_MQTT_BUFFER_SIZE    128
#define APP_CA_CERT_TAG 1
#define APP_PSK_TAG 2

static sec_tag_t m_sec_tags[] = {
#if defined(MBEDTLS_X509_CRT_PARSE_C) || defined(CONFIG_NET_SOCKETS_OFFLOAD)
APP_CA_CERT_TAG,
#endif
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__PSK_ENABLED)
APP_PSK_TAG,
#endif
};

/* Buffers for MQTT client. */
static u8_t rx_buffer[APP_MQTT_BUFFER_SIZE];
static u8_t tx_buffer[APP_MQTT_BUFFER_SIZE];
static bool connected;

#define MQTT_CLIENTID           "zephyr_publisher"

struct zsock_addrinfo *haddr;
s64_t time_base;
static struct sockaddr_storage broker;
static struct mqtt_client client_ctx;

static void clear_fds(void)
{
nfds = 0;
}
time_t my_k_time(time_t *ptr)
{
s64_t stamp;
time_t now;

stamp = k_uptime_get();
now = (time_t)((stamp + time_base) / 1000);

if (ptr) {
*ptr = now;
}

return now;
}

static void broker_init(void)
{
struct sockaddr_in *broker4 = (struct sockaddr_in *)&broker;

broker4->sin_family = AF_INET;
broker4->sin_port = htons(8883);

net_ipaddr_copy(&broker4->sin_addr,
&net_sin(haddr->ai_addr)->sin_addr);

#if defined(CONFIG_SOCKS)
struct sockaddr_in *proxy4 = (struct sockaddr_in *)&socks5_proxy;

proxy4->sin_family = AF_INET;
proxy4->sin_port = htons(1081);
inet_pton(AF_INET, "agwgaprlb6xdl-ats.iot.us-west-2.amazonaws.com", &proxy4->sin_addr);
#endif
}

void mqtt_evt_handler(struct mqtt_client *const client,
const struct mqtt_evt *evt)
{
int err;

switch (evt->type) {
case MQTT_EVT_CONNACK:
if (evt->result != 0) {
LOG_ERR("MQTT connect failed %d", evt->result);
break;
}

connected = true;
LOG_INF("MQTT client connected!");

break;

case MQTT_EVT_DISCONNECT:
LOG_INF("MQTT client disconnected %d", evt->result);

connected = false;
clear_fds();

break;

case MQTT_EVT_PUBACK:
if (evt->result != 0) {
LOG_ERR("MQTT PUBACK error %d", evt->result);
break;
}

LOG_INF("PUBACK packet id: %u", evt->param.puback.message_id);

break;

case MQTT_EVT_PUBREC:
if (evt->result != 0) {
LOG_ERR("MQTT PUBREC error %d", evt->result);
break;
}

LOG_INF("PUBREC packet id: %u", evt->param.pubrec.message_id);

const struct mqtt_pubrel_param rel_param = {
.message_id = evt->param.pubrec.message_id
};
err = mqtt_publish_qos2_release(client, &rel_param);
if (err != 0) {
LOG_ERR("Failed to send MQTT PUBREL: %d", err);
}

break;

case MQTT_EVT_PUBCOMP:
if (evt->result != 0) {
LOG_ERR("MQTT PUBCOMP error %d", evt->result);
break;
}

LOG_INF("PUBCOMP packet id: %u",
evt->param.pubcomp.message_id);

break;

default:
break;
}
}


static void client_init(struct mqtt_client *client)
{
        static struct mqtt_utf8 password;
        static struct mqtt_utf8 username;

mqtt_client_init(client);
broker_init();


password.utf8 = (u8_t *)CONFIG_SAMPLE_CLOUD_AWS_PASSWORD;
password.size = strlen(CONFIG_SAMPLE_CLOUD_AWS_PASSWORD);

client->password = &password;

username.utf8 = (u8_t *)CONFIG_SAMPLE_CLOUD_AWS_USERNAME;
username.size = strlen(CONFIG_SAMPLE_CLOUD_AWS_USERNAME);

client->user_name = &username;


/* MQTT client configuration */
client->broker = &broker;
client->evt_cb = mqtt_evt_handler;
client->client_id.utf8 = (u8_t *)MQTT_CLIENTID;
client->client_id.size = strlen(MQTT_CLIENTID);
client->password = NULL;
client->user_name = NULL;
client->protocol_version = MQTT_VERSION_3_1_1;

/* MQTT buffers configuration */
client->rx_buf = rx_buffer;
client->rx_buf_size = sizeof(rx_buffer);
client->tx_buf = tx_buffer;
client->tx_buf_size = sizeof(tx_buffer);

client->transport.type = MQTT_TRANSPORT_SECURE;

struct mqtt_sec_config *tls_config = &client->transport.tls.config;

tls_config->peer_verify = TLS_PEER_VERIFY_REQUIRED;
tls_config->cipher_list = NULL;
tls_config->sec_tag_list = m_sec_tags;
tls_config->sec_tag_count = ARRAY_SIZE(m_sec_tags);
tls_config->hostname = "agwgaprlb6xdl-ats.iot.us-west-2.amazonaws.com";
client->transport.type = MQTT_TRANSPORT_SECURE;
#if defined(CONFIG_SOCKS)
mqtt_client_set_proxy(client, &socks5_proxy,
socks5_proxy.sa_family == AF_INET ?
sizeof(struct sockaddr_in) :
sizeof(struct sockaddr_in6));
#endif


}
#define RC_STR(rc) ((rc) == 0 ? "OK" : "ERROR")
#define PRINT_RESULT(func, rc) \
LOG_INF("%s: %d <%s>", (func), rc, RC_STR(rc))
static void prepare_fds(struct mqtt_client *client)
{
if (client->transport.type == MQTT_TRANSPORT_NON_SECURE) {
fds[0].fd = client->transport.tcp.sock;
}
#if defined(CONFIG_MQTT_LIB_TLS)
else if (client->transport.type == MQTT_TRANSPORT_SECURE) {
fds[0].fd = client->transport.tls.sock;
}
#endif

fds[0].events = ZSOCK_POLLIN;
nfds = 1;
}

static void wait(int timeout)
{
if (nfds > 0) {
if (poll(fds, nfds, timeout) < 0) {
LOG_ERR("poll error: %d", errno);
}
}
}



static int try_to_connect(struct mqtt_client *client)
{
u8_t retries = 3U;
int rc;

LOG_DBG("attempting to connect...");

client_init(client);
rc = mqtt_connect(client);
if (rc != 0) {
PRINT_RESULT("mqtt_connect", rc);
k_sleep(500);
} else {

prepare_fds(client);

wait(500);
mqtt_input(client);
if (!connected) {
LOG_INF("Aborting connection\n");
mqtt_abort(client);
}

}
if (connected) {
return 0;
}

return -EINVAL;

}


static int tls_init(void)
{
        int err = -EINVAL;
LOG_INF("Ca size:%d\n", sizeof(ca_certificate));
        err = tls_credential_add(APP_CA_CERT_TAG, TLS_CREDENTIAL_CA_CERTIFICATE,
                                 ca_certificate, sizeof(ca_certificate));
        if (err < 0) {
                LOG_ERR("Failed to register public certificate: %d", err);
                return err;
        }


        return err;
}


void mqtt_startup(char *hostname, int port)
{
struct mqtt_client *client = &client_ctx;
int retries = 5;
int err, cnt;
static struct zsock_addrinfo hints;
int res = 0;
int rc;




hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
cnt = 0;
while ((err = getaddrinfo("agwgaprlb6xdl-ats.iot.us-west-2.amazonaws.com", "8883", &hints,
&haddr)) && cnt < 3) {
LOG_ERR("Unable to get address for broker, retrying");
cnt++;
}
if (err != 0) {
LOG_ERR("Unable to get address for broker, error %d",
res);
return;
}
LOG_INF("DNS resolved for agwgaprlb6xdl-ats.iot.us-west-2.amazonaws.com:8833");
try_to_connect(client);
PRINT_RESULT("try_to_connect", rc);




}

static void show_addrinfo(struct addrinfo *addr)
{
char hr_addr[NET_IPV6_ADDR_LEN];
void *a;

top:
LOG_DBG("  flags   : %d", addr->ai_flags);
LOG_DBG("  family  : %d", addr->ai_family);
LOG_DBG("  socktype: %d", addr->ai_socktype);
LOG_DBG("  protocol: %d", addr->ai_protocol);
LOG_DBG("  addrlen : %d", (int)addr->ai_addrlen);

/* Assume two words. */
LOG_DBG("   addr[0]: 0x%lx", ((uint32_t *)addr->ai_addr)[0]);
LOG_DBG("   addr[1]: 0x%lx", ((uint32_t *)addr->ai_addr)[1]);

if (addr->ai_next != 0) {
addr = addr->ai_next;
goto top;
}

a = &net_sin(addr->ai_addr)->sin_addr;
LOG_INF("  Got %s",
log_strdup(net_addr_ntop(addr->ai_family, a,
hr_addr, sizeof(hr_addr))));

}

void do_sntp(struct addrinfo *addr)
{
struct sntp_ctx ctx;
int rc;
s64_t stamp;
struct sntp_time sntp_time;
char time_str[sizeof("1970-01-01T00:00:00")];

LOG_INF("Sending NTP request for current time:");

/* Initialize sntp */
rc = sntp_init(&ctx, addr->ai_addr, sizeof(struct sockaddr_in));
if (rc < 0) {
LOG_ERR("Unable to init sntp context: %d", rc);
return;
}
rc = sntp_query(&ctx, K_FOREVER, &sntp_time);
if (rc == 0) {
stamp = k_uptime_get();
time_base = sntp_time.seconds * MSEC_PER_SEC - stamp;

/* Convert time to make sure. */
time_t now = sntp_time.seconds;
struct tm now_tm;

gmtime_r(&now, &now_tm);
strftime(time_str, sizeof(time_str), "%FT%T", &now_tm);
LOG_INF("  Acquired time: %s", log_strdup(time_str));

} else {
LOG_ERR("  Failed to acquire SNTP, code %d\n", rc);
}

sntp_close(&ctx);
}


void main(void)
{
static struct addrinfo hints;
struct addrinfo *haddr;
int res;
int cnt = 0;
        int rc;


app_dhcpv4_startup();

LOG_INF("Should have DHCPv4 lease at this point.");
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = 0;
//while ((res = getaddrinfo("console.aws.amazon.com", "80", &hints,
while ((res = getaddrinfo("time.google.com", "123", &hints,
&haddr)) && cnt < 3) {
LOG_ERR("Unable to get address for NTP server, retrying");
cnt++;
}

if (res != 0) {
LOG_ERR("Unable to get address of NTP server, exiting %d", res);
return;
}


LOG_INF("DNS resolved for console.aws.amazon.com:80");
show_addrinfo(haddr);
do_sntp(haddr);

#if defined(CONFIG_MQTT_LIB_TLS)

        rc = tls_init();
        PRINT_RESULT("tls_init", rc);
#endif

mqtt_startup("agwgaprlb6xdl-ats.iot.us-west-2.amazonaws.com", 8883);

}

Console Logs:

[00:00:09.666,000] <inf> aws_mqtt: tls_init: 0 <OK>
[00:00:09.706,000] <inf> aws_mqtt: DNS resolved for agwgaprlb6xdl-ats.iot.us-west-2.amazonaws.com:8833
[00:00:09.718,000] <dbg> aws_mqtt.try_to_connect: attempting to connect...
[00:00:09.727,000] <dbg> net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20401bac): Created socket 0
[00:00:09.739,000] <dbg> net_mqtt_sock_tls.mqtt_client_tls_connect: (0x20401bac): Before Connect completed


Zephyr 2.2.0-rc3 tagged

Johan Hedberg
 

Hi Zephyr developers,

We have now tagged Zephyr 2.2.0-rc3, i.e. we’re getting close to the final release. We’re currently at 15 medium priority bugs and no high priority bugs, so the release criteria are met (at least for now).

From now on I’ll handle all merges until the release. The focus should now be on testing, documentation updates and release notes. If all goes well the final release will be done later in the coming week.

The full release log can be found here: https://github.com/zephyrproject-rtos/zephyr/releases/tag/v2.2.0-rc3

More details about Zephyr releases is found here: https://github.com/zephyrproject-rtos/zephyr/wiki/Program-Management

Thanks to everybody who has contributed to this release!

Johan