This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Thingy:91 + Azure IoT Hub


Hi,

I am trying to use the thingy91 to publish some sensor data to an Azure IoT Hub, I've tried to look at mqtt_simple and modified "asset_tracker" application but I couldn't succeed.

so is there any example showing how to publish data to Azure IoT Hub (MQTT broker) using thingy91?

Thank you in advance...

Parents
  • Hello, 

    Can you provide some more information on what is failing? Are you able to connect the server? Do you get any errors?

    We have an unofficial example project called Bifravst which will connect the Thingy:91 to Azure. This is however work in progress, and I urge to read through what is documented.

    Kind regards,
    Øyvind

  • You may also want to look at this github PR which will be part of NCS 1.4.0, when that is released.
    -Øyvind

  • Deri said:
    I have to run the flash twice to program my device properly. any suggestions to solve this issue?

    Can you try running west flash --erase?

    Deri said:
    It is the same build image that has been flashed on two devices (Thingy91) and the same SIM card, please look at the log files of both devices to figure out why does it show this error message?

    I will need some more time to look into this case. Have you tried an unmodified version of the Azure IoT Hub sample on both? Only adding relevant information to connect?

      

  • Part 1: # west flash --erase it works correctly, thanks.

    Part 2:I followed the below steps and got some errors:

    #C:\ncs\nrf\samples\nrf9160>git checkout master
    #git pull
    #cd azure_iot_hub
    #copy NUL prj_thingy91_nrf9160ns.conf
    #cd ../../../..
    C:\ncs>
    #set ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb
    #set GNUARMEMB_TOOLCHAIN_PATH=c:\gnuarmemb
    #zephyr\zephyr-env.cmd
    #cd nrf\samples\nrf9160\azure_iot_hub
    #west build -b thingy91_nrf9160ns -d build
    -- west build: generating a build system
    Including boilerplate (Zephyr base): C:/ncs/zephyr/cmake/app/boilerplate.cmake
    -- Application: C:/ncs/nrf/samples/nrf9160/azure_iot_hub
    -- Zephyr version: 2.3.0-rc1 (C:/ncs/zephyr)
    -- Found Python3: C:/Python38/python.exe (found suitable exact version "3.8.5") found components: Interpreter
    -- Board: thingy91_nrf9160ns
    No board named 'thingy91_nrf9160ns' found
    -- The C compiler identification is unknown
    -- The CXX compiler identification is unknown
    CMake Error at C:/ncs/zephyr/cmake/extensions.cmake:1486 (project):
      No CMAKE_C_COMPILER could be found.
    
      Tell CMake where to find the compiler by setting either the environment
      variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
      the compiler, or to the compiler name if it is in the PATH.
    Call Stack (most recent call first):
      C:/ncs/zephyr/cmake/app/boilerplate.cmake:409 (print_usage)
      C:/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
      CMakeLists.txt:9 (find_package)
    
    
    CMake Error at C:/ncs/zephyr/cmake/extensions.cmake:1486 (project):
      No CMAKE_CXX_COMPILER could be found.
    
      Tell CMake where to find the compiler by setting either the environment
      variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
      to the compiler, or to the compiler name if it is in the PATH.
    Call Stack (most recent call first):
      C:/ncs/zephyr/cmake/app/boilerplate.cmake:409 (print_usage)
      C:/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/ncs/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
      CMakeLists.txt:9 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    See also "C:/ncs/nrf/samples/nrf9160/azure_iot_hub/build/CMakeFiles/CMakeOutput.log".
    See also "C:/ncs/nrf/samples/nrf9160/azure_iot_hub/build/CMakeFiles/CMakeError.log".
    FATAL ERROR: command exited with status 1: 'C:\Program Files\CMake\bin\cmake.EXE' '-BC:\ncs\nrf\samples\nrf9160\azure_iot_hub\build' '-SC:\ncs\nrf\samples\nrf9160\azure_iot_hub' -GNinja -DBOARD=thingy91_nrf9160ns
    

    -The prj_thingy91_nrf9160ns.conf file filled with below configuration

    #
    # Copyright (c) 2020 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
    #
    
    # General config
    CONFIG_LOG=y
    
    # NEWLIB C
    CONFIG_NEWLIB_LIBC=y
    
    # Network
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_NETWORK_MODE_LTE_M=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    
    # BSD library
    CONFIG_BSD_LIBRARY=y
    
    # AT Host
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_AT_HOST_LIBRARY=y
    CONFIG_AT_CMD_THREAD_STACK_SIZE=2048
    
    # Azure IoT Hub library
    CONFIG_AZURE_IOT_HUB=y
    CONFIG_AZURE_IOT_HUB_DEVICE_ID="Thingy91"
    # Host name must be configured if DPS is not used
    CONFIG_AZURE_IOT_HUB_HOSTNAME="Nordic.azure-devices.net"
    # Change the security tag to the tag where Azure IoT Hub certificates
    # are provisioned
    CONFIG_AZURE_IOT_HUB_SEC_TAG=10
    
    # Uncomment and configure the options below to use DPS for device provisioning
    # CONFIG_AZURE_IOT_HUB_DPS=y
    # CONFIG_AZURE_IOT_HUB_DPS_ID_SCOPE=""
    
    # Uncomment to get more verbose logging when debugging
    # CONFIG_AZURE_IOT_HUB_LOG_LEVEL_DBG=y
    
    # LED control
    CONFIG_DK_LIBRARY=y
    CONFIG_DK_LIBRARY_INVERT_LEDS=n
    
    # Heap and stacks
    CONFIG_HEAP_MEM_POOL_SIZE=4096
    
    CONFIG_HW_STACK_PROTECTION=y
    
    # cJSON
    CONFIG_CJSON_LIB=y
    
    # Settings, needed for Azure Device Provisioning Service
    CONFIG_FLASH=y
    CONFIG_FLASH_MAP=y
    CONFIG_FCB=y
    CONFIG_SETTINGS=y
    CONFIG_SETTINGS_FCB=y
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    

  • Deri said:
    Part 1: # west flash --erase it works correctly, thanks.

    Excellent!

    Deri said:
    Part 2:I followed the below steps and got some errors:

     Have you run west update after doing git pull?

  • I have succeeded to compile my code after running #west update , but I got an error to connect to Azure IoT hub:

    Please look at the log file.

    +CSCON: 0
    RRC mode: Idle
    *** Booting Zephyr OS build zephyr-v2.4.0-198-ga4ead9805140  ***
    Flash regions		Domain		Permissions
    00 00 0x00000 0x08000 	Secure		rwxl
    01 31 0x08000 0x100000 	Non-Secure	rwxl
    
    Non-secure callable region 0 placed in flash region 0 with size 32.
    
    SRAM region		Domain		Permissions
    00 07 0x00000 0x10000 	Secure		rwxl
    08 31 0x10000 0x40000 	Non-Secure	rwxl
    
    Peripheral		Domain		Status
    00 NRF_P0               Non-Secure	OK
    01 NRF_CLOCK            Non-Secure	OK
    02 NRF_RTC0             Non-Secure	OK
    03 NRF_RTC1             Non-Secure	OK
    04 NRF_NVMC             Non-Secure	OK
    05 NRF_UARTE1           Non-Secure	OK
    06 NRF_UARTE2           Secure		SKIP
    07 NRF_TWIM2            Non-Secure	OK
    08 NRF_SPIM3            Non-Secure	OK
    09 NRF_TIMER0           Non-Secure	OK
    10 NRF_TIMER1           Non-Secure	OK
    11 NRF_TIMER2           Non-Secure	OK
    12 NRF_SAADC            Non-Secure	OK
    13 NRF_PWM0             Non-Secure	OK
    14 NRF_PWM1             Non-Secure	OK
    15 NRF_PWM2             Non-Secure	OK
    16 NRF_PWM3             Non-Secure	OK
    17 NRF_WDT              Non-Secure	OK
    18 NRF_IPC              Non-Secure	OK
    19 NRF_VMC              Non-Secure	OK
    20 NRF_FPU              Non-Secure	OK
    21 NRF_EGU1             Non-Secure	OK
    22 NRF_EGU2             Non-Secure	OK
    23 NRF_DPPIC            Non-Secure	OK
    24 NRF_GPIOTE1          Non-Secure	OK
    25 NRF_REGULATORS       Non-Secure	OK
    
    SPM: NS image at 0xc000
    SPM: NS MSP at 0x200271c8
    SPM: NS reset vector at 0x1077d
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build zephyr-v2.4.0-198-ga4ead9805140  ***
    Azure IoT Hub sample started
    Connecting to LTE network
    +CEREG: 2,"8602","04CAA80A",7,0,0,"11100000","11100000"
    LTE cell changed: Cell ID: 80390154, Tracking area: 34306
    PSM parameter update: TAU: -1, Active time: -1
    +CSCON: 1
    RRC mode: Connected
    +CEREG: 1,"8602","04CAA80A",7,,,"11100000","11100000"
    Network registration status: Connected - home network
    Connected to LTE network
    AZURE_IOT_HUB_EVT_CONNECTING
    azure_iot_hub_connect failed: -95
    [00:00:03.208,160] <dbg> azure_iot_hub.broker_init: IPv4 Address found 13.79.172.43
    [00:00:03.793,762] <err> azure_iot_hub: mqtt_connect, error: -95
    +CSCON: 0
    RRC mode: Idle
    

    I've added the below to prj_thingy91_nrf9160ns.conf

    CONFIG_AZURE_IOT_HUB_DEVICE_ID="Thingy91"
    CONFIG_AZURE_IOT_HUB_HOSTNAME="Nordic.azure-devices.net"
    In addition to , I've added the password into azure_iot_hub.c as follows:
    static int client_broker_init(struct mqtt_client *const client, bool dps)
    {
    	int err;
    	static sec_tag_t sec_tag_list[] = { CONFIG_AZURE_IOT_HUB_SEC_TAG };
    	struct mqtt_sec_config *tls_cfg = &(client->transport).tls.config;
    
    	mqtt_client_init(client);
    
    	err = broker_init(dps);
    	if (err) {
    		return err;
    	}
    
    	/* The following parameters differ between DPS and IoT hub:
    	 *	client->user_name
    	 *	tls_cfg->hostname
    	 */
    	
    	char * token ="SharedAccessSignature sr=Nordic.azure-devices.net%2Fdevices%2FThingy91&sig=JH5dvWZ98gjAnUIEDm%2B8sN3ZBHmPzDvaZbFT%2FYdQOa0%3D&se=3600001600713127";
    	struct mqtt_utf8 pass;
    	pass.utf8 = (uint8_t*)token ;
    	pass.size = (uint32_t)strlen(token);
    
    	client->broker			= &broker;
    	client->evt_cb			= mqtt_evt_handler;
    	client->client_id.utf8	= conn_config.device_id;
    	client->client_id.size	= strlen(conn_config.device_id);
    	client->password		= &pass;
  • Hi,

    Is there any update about my case using the "Azure IoT Hub sample"? are there missing configurations should I add to prj_thingy91_nrf9160ns.conf? I got the same results using both devices of Thingy91.

Reply Children
  • Looks like you still have an issue with your certificates, often giving -95 (EOPNOTSUPP). 

    #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */

    Have you added the certificates correctly to nrf\samples\nrf9160\azure_iot_hub\certs\certificates.h?

  • yes, Please look at certificates.h


    /*
     * Copyright (c) 2020 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
     */
    //#include "ca-cert.pem"
    static const unsigned char ca_certificate[] =
    "-----BEGIN CERTIFICATE-----\r\n"
    "MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJJ\r\n"
    "RTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJlclRydXN0MSIwIAYD\r\n"
    "VQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTAwMDUxMjE4NDYwMFoX\r\n"
    "DTI1MDUxMjIzNTkwMFowWjELMAkGA1UEBhMCSUUxEjAQBgNVBAoTCUJhbHRpbW9y\r\n"
    "ZTETMBEGA1UECxMKQ3liZXJUcnVzdDEiMCAGA1UEAxMZQmFsdGltb3JlIEN5YmVy\r\n"
    "VHJ1c3QgUm9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKMEuyKr\r\n"
    "mD1X6CZymrV51Cni4eiVgLGw41uOKymaZN+hXe2wCQVt2yguzmKiYv60iNoS6zjr\r\n"
    "IZ3AQSsBUnuId9Mcj8e6uYi1agnnc+gRQKfRzMpijS3ljwumUNKoUMMo6vWrJYeK\r\n"
    "mpYcqWe4PwzV9/lSEy/CG9VwcPCPwBLKBsua4dnKM3p31vjsufFoREJIE9LAwqSu\r\n"
    "XmD+tqYF/LTdB1kC1FkYmGP1pWPgkAx9XbIGevOF6uvUA65ehD5f/xXtabz5OTZy\r\n"
    "dc93Uk3zyZAsuT3lySNTPx8kmCFcB5kpvcY67Oduhjprl3RjM71oGDHweI12v/ye\r\n"
    "jl0qhqdNkNwnGjkCAwEAAaNFMEMwHQYDVR0OBBYEFOWdWTCCR1jMrPoIVDaGezq1\r\n"
    "BE3wMBIGA1UdEwEB/wQIMAYBAf8CAQMwDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3\r\n"
    "DQEBBQUAA4IBAQCFDF2O5G9RaEIFoN27TyclhAO992T9Ldcw46QQF+vaKSm2eT92\r\n"
    "9hkTI7gQCvlYpNRhcL0EYWoSihfVCr3FvDB81ukMJY2GQE/szKN+OMY3EU/t3Wgx\r\n"
    "jkzSswF07r51XgdIGn9w/xZchMB5hbgF/X++ZRGjD8ACtPhSNzkE1akxehi/oCr0\r\n"
    "Epn3o0WC4zxe9Z2etciefC7IpJ5OCBRLbf1wbWsaY71k5h+3zvDyny67G7fyUIhz\r\n"
    "ksLi4xaNmjICq44Y3ekQEe5+NauQrz4wlHrQMz2nZQ/1/I6eYs9HRCwBXbsdtTLS\r\n"
    "R9I4LtD+gdwyah617jzV/OeBHRnDJELqYzmp\r\n"
    "-----END CERTIFICATE-----\r\n"
    ;
    
    static const unsigned char private_key[] = {
    #include "private-key.pem"
    };
    
    static const unsigned char device_certificate[] = {
    #include "client-cert.pem"
    };
    

Related