Skip navigation
Home > All Places > WICED Studio Wi-Fi/Combo > WICED Studio Wi-Fi/Combo Forums > Blog > 2016 > August
2016
AndrewY_86

Using Aliyun MNS Service

Posted by AndrewY_86 Aug 25, 2016

Aliyun is a cloud service provider that supports a messaging service called Aliyun MNS. Messages and commands are transmitted using RESTful HTTP methods. This blog provides an application and a guide to interfacing with the Aliyun MNS service.

 

Creating an Account:

  1. Create an account at http://intl.aliyun.com( for users outside of China ) by clicking on "Free Trial"
  2. 1.PNG
  3. After verifying your account and adding a payment method (MNS Service is free as of time of writing), log in to http://console.aliyun.com
  4. Click on the gear icon next to the "Products" drop down list and add the "Message Service"
  5. 2.PNG

 

Creating Account Settings:

  1. Click on the newly added "Message Service" tab or navigate to http://mns.console.aliyun.com
  2. The locations listed next to "Queue list" are the locations of the servers for the messaging service. Select one and click on "Get endpoint"
  3. 3.PNG
  4. The format of the public endpoint is (accountid).mns.(region).aliyuncs.com. Make note of the account ID and region
  5. Close the popup window and click on "AccessKeys" on the top menu bar or navigate to https://ak-console.aliyun.com
  6. A "Security Tips" popup will appear, click on continue to proceed
  7. 4.PNG
  8. Click on "Create Access Key", read the API Terms of Use, then "Agree and Create"
  9. Make note of the "Access Key ID" and the "Access Key Secret"

 

Running the Application:

  1. Download and unzip the application to your snip folder
  2. Open aliyun_common.h and fill in the previously noted information. ALIYUN_QUEUE_NAME is the name of the queue you want to create or work on
  3. Configure wifi_config_dct.h for your AP settings
  4. Build and download the application with the make target snip.aliyun_mns-<platform> download run
  5. Open a terminal application to view the output
  6. 5.PNG
  7. You can also send/receive messages on the web console (comment the call to delete queue to verifymessages sent from wiced board)
  8. 6.PNG

Aliyun API reference documents can be found here: https://intl.aliyun.com/help/product/27412.htm?spm=a3c0i.men.a1.3.3adntp

seyhana_

OTA2 Update for SDK-3.7.0

Posted by seyhana_ Aug 23, 2016

Attached is the OTA2 update files for SDK-3.7.0.

 

The BCM943907AEVAL1F_1 evaluation board is used for updating firmware over the air firmware update.

The sample firmware is build for BCM943907AEVAL1F_1 using ota2_example and scan snip applications for future firmware to updates.

 

Extract the content of the attached compressed file OTA2Update_WicedSDK-3.7.0.tgz into Wiced SDK-3.7.0 release.

Content of OTA2Update_WicedSDK-3.7.0.tgz:

 

apps/snip/ota2_example/ota2_example.mk

apps/snip/ota2_example/ota2_test.c

apps/snip/ota2_example/ota2_test.h

apps/snip/ota2_example/ota2_test_config.c

apps/snip/ota2_example/ota2_test_config.h

apps/snip/ota2_example/ota2_test_dct.c

apps/snip/ota2_example/ota2_test_dct.h

apps/snip/ota2_example/wifi_config_dct.h

apps/snip/ota2_extract/ota2_extract.c

apps/snip/ota2_extract/ota2_extract.mk

apps/snip/scan/scan.c

apps/snip/scan/scan.mk

apps/snip/scan/wifi_config_dct.h

libraries/daemons/ota2_server/ota2_server.c

libraries/daemons/ota2_server/ota2_server.h

libraries/daemons/ota2_server/ota2_server.mk

libraries/daemons/ota2_server/ota2_server_web_page.c

libraries/daemons/ota2_server/ota2_server_web_page.h

libraries/daemons/ota2_server/wiced_ota2_server.c

libraries/daemons/ota2_server/wiced_ota2_server.h

libraries/daemons/ota2_service/ota2_service.mk

libraries/daemons/ota2_service/wiced_ota2_network.c

libraries/daemons/ota2_service/wiced_ota2_network.h

libraries/daemons/ota2_service/wiced_ota2_service.c

libraries/daemons/ota2_service/wiced_ota2_service.h

libraries/utilities/command_console/dct/command_console_dct.c

libraries/utilities/command_console/dct/command_console_dct.h

libraries/utilities/command_console/dct/dct.mk

WICED/platform/MCU/wiced_dct_external_common.c

WICED/platform/MCU/wiced_dct_internal_common.c

tools/makefiles/wiced_apps.mk

 

1.

Build the snip.ota2_extract snip application first. The ota_extract elf file is needed by the snip.ota2_example and snip.scan will be build later. The ota2_extact elf file could be found in .../build/snip.ota2_extract-BCM943907AEVAL1F_1.B1/binary/snip.ota2_extract-BCM943907AEVAL1F_1.B1.stripped.elf OTA  location.

 

Use the following make target command to build the ota2_extract:

     snip.ota2_extract-<Platform>

     snip.ota2_extract-BCM943907AEVAL1F_1.B1

 

2.

Build snip.scan snip application that simulates the new firmware that will updated using OTA. Building snip.scan will cause the firmware to be downloaded to the target device.

 

Use the following make target to build the snip.scan:

     snip.scan-BCM943907AEVAL1F_1.B1 ota2_image

 

3.

Build the snip.ota2_example snip application using the attached snip.ota2_example files.

 

This snip application demonstrates a firmware upgrade using OTA by following means:

- Command like interface to initiate new firmware update using over the air

- The target device could be brought up as an Soft-AP and new firmware update could be initiated using html page served by the target device.

 

Use the following make target to build the snip.ota2_example:

     snip.ota2_example-BCM943907AEVAL1F_1.B1 download download_apps ota2_image run

 

4.

As a result of building snip.ota2_example and snip.scan application binary files will be generated for each build. These binary files will be used to update the firmware on the device using OTA. Initial release of firmware snip.ota2_example will be updated by snip.scan then back to snip.ota2_example.

 

The /build/snip.ota2_example-BCM943907AEVAL1F_1.B1/OTA2_image_file.bin is named as OTA2ExampleFW.bin

The /build/snip.scan-BCM943907AEVAL1F_1.B1/OTA2_image_file.bin binary file is renamed as FW2BeUpdatedUsingOTA.bin

The both binary files are attached as reference only.

 

Both binary files are copied into the web server default file server location. In this case, mongoose (is used to serve the firmware binary files to be pulled and pushed by the target device.

 

The default port used by the ota2_example is port 80. Either the web server port could be changed to match the ota2_example port number or web server port number could be passed to the ota2_example.

 

5.

After building and loading the loading the snip.ota2_example to the target, by default the target device boots and tries to connect to the AP defined in /apps/snip/ota2_example/wifi_config_dct.h.

 

#define CLIENT_AP_SSID       "BroadcomSA_24"
#define CLIENT_AP_PASSPHRASE "123456789SA"

 

Connect the device that running the web server to the same network as the target device (BCM943907AEVAL1F_1) is connected. In this case the windows laptop is also connected to  BroadcomSA_24 and has the IP address of 192.168.0.100.

 

Using the snip.ota2_example application, the command line interface is used to initiate a new firmware update using OTA.

 

Issue the following command to start OTA of the snip.scan application as new firmware to update.

     get_update <web-server>/<New Firmware To OTA>

    

In this case, below command is used to initiate a new firmware to be pulled down to the target device:

     get_update 192.168.0.100/FW2BeUpdatedUsingOTA.bin

 

> get_update 192.168.0.100/FW2BeUpdatedUsingOTA.bin

> PLAYER_EVENT_GET_UPDATE !

ota2_test_get_update() player->ota2_bg_service 0x0

ota2_test_get_update() wiced_ota2_service_init() bg_service:0x505c80

Download the OTA Image file - get it NOW!

wiced_ota2_service_network_switch_to_ota2_ap() network to switch to.

----------------------------- OTA2 Service Called : AP_CONNECTED -----------------------------

        return SUCESS (not used by service). This is informational

Try 0 Connecting to 192.168.0.100:80  (192.168.0.100) !

----------------------------- OTA2 Service Called : SERVER_CONNECTED -----------------------------

        return SUCESS (not used by service). This is informational

----------------------------- OTA2 Service Called : UPDATE_AVAILABLE -----------------------------

        return SUCCESS, let Service perform the download.

Try 0 Connecting to 192.168.0.100:80  (192.168.0.100) !

----------------------------- OTA2 Service Called : SERVER_CONNECTED -----------------------------

        return SUCESS (not used by service). This is informational

----------------------------- OTA2 Service Called : PERFORM_UPDATE -----------------------------

        return SUCCESS, let Service extract update on next reboot.

Set  WICED_OTA2_IMAGE_EXTRACT_ON_NEXT_BOOT!

 

 

After download, reboot the target by "update_reboot" to extract the new firmware.

After extract, reboot the target again to start new firmware running.

 

Note: A full terminal output is attached as well.

 

6.

Now the updated firmware of snip.scan is running on the target.

If the button 1 (push button connected between BCM943907AEVAL1F_1 J6-2 and gnd) on target is pressed and hold at reset of the target and released after 5 seconds of reset, the target device boots as Soft-AP with SSID and passphrase defined in the /apps/snip/scan/wifi_config_dct.h

 

#define SOFT_AP_SSID         "Scan WICED Soft AP"
#define SOFT_AP_PASSPHRASE   "abcd1234"

 

Connect the client device to the "Scan WICED Soft AP" where the OTA2ExampleFW.bin binary is located.

 

Using a web browser on the client device open the default web page of the target device.

The target device IP address is printed on the terminal:

Hi, I'm the OTA2 extraction app (ota2_extract).

IPv4 network ready IP: 192.168.10.1

Setting IPv6 link-local address

IPv6 network ready IP: FE80:0000:0000:0000:9AF1:70FF:FE6F:7D92

Using "Choose File" select the next firmware to update. In this case the snip.ota2_example firmware will be loaded back on the target by pushing new firmware to target via OTA.

 

Same above step could be done using snip.ota2_example snip application running on the target. In this case the target device will boot up as Soft-AP where the SSID and passphrase defined in the /apps/snip/ota2_example/wifi_config_dct.h

 

#define SOFT_AP_SSID         "Ota2Ex WICED Soft AP"
#define SOFT_AP_PASSPHRASE   "abcd1234"

 

 

7. DCT Structure Update for OTA

 

After the device firmware is updated using OTA2, the DCT data is updated from previous version to new version. For OTA2 example the version of the Wiced SDK is used for reference. Final device could use different version number then the Wiced SDK and incorporate SDK to final product changes into one. Existing DCT data structures are copied to new DCT structures and new locations. Any updates on the DCT by new version are implemented by the following files in the Wiced SDK:

 

.../WICED/platform/MCU/wiced_dct_external_common.c

.../WICED/platform/MCU/wiced_dct_external_ota2.c

.../WICED/platform/MCU/wiced_dct_internal_common.c

.../WICED/platform/MCU/wiced_dct_internal_ota2.c

 

  The DCT structure is defined in the .../WICED/platform/include/platform_dct.h used by the OTA application to update the DCT data.

 

/* The structure for the complete system DCT layout.
 * The application DCT data follows this structure in the DCT section of FLASH.
 */
typedef struct
{
    platform_dct_header_t               dct_header;
    platform_dct_mfg_info_t             mfg_info;
    platform_dct_security_t             security_credentials;
    platform_dct_wifi_config_t          wifi_config;
    platform_dct_ethernet_config_t      ethernet_config;
    platform_dct_network_config_t       network_config;
    platform_dct_bt_config_t            bt_config;
    platform_dct_p2p_config_t           p2p_config;
    platform_dct_ota2_config_t          ota2_config;
    platform_dct_version_t              dct_version;
} platform_dct_data_t;

 

 

The DCT offsets are defined in the wiced_dct_external_common.c to copy the DCT data corresponding locations.

 

static const uint32_t DCT_section_offsets[ ] =
{
    [DCT_APP_SECTION]           = sizeof(platform_dct_data_t),
    [DCT_SECURITY_SECTION]      = OFFSETOF( platform_dct_data_t, security_credentials ),
    [DCT_MFG_INFO_SECTION]      = OFFSETOF( platform_dct_data_t, mfg_info ),
    [DCT_WIFI_CONFIG_SECTION]   = OFFSETOF( platform_dct_data_t, wifi_config ),
#ifdef WICED_DCT_INCLUDE_BT_CONFIG
    [DCT_BT_CONFIG_SECTION] = OFFSETOF( platform_dct_data_t, bt_config ),
#endif
    [DCT_INTERNAL_SECTION]      = 0,
};

 

The new DCT structures are updated with the existing data from the device by wiced_result_t wiced_dct_external_dct_update(…) in ../platform/MCU/wiced_dct_external_common.c

 

/*
 * dct_source       - Start address of the DCT to read from to update to current SDK's DCT layout
 * dct_destination  - Start address of the DCT to write current SDK's DCT layout
 */
static wiced_result_t wiced_dct_external_dct_update(uint32_t dct_destination, uint32_t dct_source)

 

For example the WiFi configuration (platform_dct_wifi_config_t ) is updated by the wiced_dct_update_wifi_config_to_current(…) call in ../platform/MCU/wiced_dct_external_common.c

 

/* wifi config */
memset( dst_dct_buffer, 0x00, LARGEST_DCT_SUB_STRUCTURE_SIZE);
if (sflash_read( &sflash_handle, (dct_source + OFFSETOF(bootloader_dct_data_t, wifi_config)), src_dct_buffer, sizeof(platform_dct_wifi_config_t)) == WICED_SUCCESS)
{
    if (wiced_dct_update_wifi_config_to_current((platform_dct_wifi_config_t*)dst_dct_buffer, (platform_dct_wifi_config_t*)src_dct_buffer) == WICED_SUCCESS)
    {
        if ( sflash_write( &sflash_handle, dct_destination + OFFSETOF(platform_dct_data_t, wifi_config), dst_dct_buffer, sizeof(platform_dct_wifi_config_t) ) != PLATFORM_SUCCESS)
        {
            goto _update_fail;
        }
    }
}

 

Any specific changes made in the WiFi configuration could be included in the wiced_dct_update_wifi_config_to_current(…). Currently the current data is copied to the new DCT structure and any specific changes could be incorporated into here.

 

wiced_result_t wiced_dct_update_wifi_config_to_current (platform_dct_wifi_config_t* wifi_config_destination,
                                                        platform_dct_wifi_config_t* wifi_config_source)

 

 

Currently OTA2 is tested on the BCM43907 and BCM43909 based platforms.

Support for other platforms will be available soon.

Step 1. Alter board specific platform.c so that ADC1 utilizes ADC_Channel_16.

 

Step 2. Copy the following code snip into your application and execute.

 

wiced_adc_t adc = WICED_ADC_1;
uint16_t mV;
float celsius;
uint32_t sample_cycle = 10;

/*init proper channel*/
wiced_adc_init(adc, sample_cycle); 

/*this in combination with switching to proper ADC channel is what allows temp sensor to be read*/     
ADC_TempSensorVrefintCmd(1); 

/*sample channel*/
wiced_adc_take_sample(adc, &mV);

/*conversion of mV to celsius--see datasheet*/
celsius = (float)mV;
celsius *= 3300;
celsius /= 0xfff;
celsius /= 1000.0;
celsius -= 0.760;
celsius /= .0025;
celsius += 25.0;

WPRINT_BT_APP_INFO(("***** Temperature in deg C =  %f ***** \n\r", celsius));

 

 

Specifics of conversion formula can be found in the datasheet. For more info on the implementation of conversion see: ARM Processors (Discovering the STM32F4): Working with STM32F4 Temperature Sensor

 

Jacob

Filter Blog

By date:
By tag: