国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

RT-Thread 軟件包-IoT-OneNET①

這篇具有很好參考價值的文章主要介紹了RT-Thread 軟件包-IoT-OneNET①。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

RT-Thread 軟件包-IoT-OneNET①

RT-Thread 軟件包-IoT-OneNET①,Linux,Python,ARM?MCU,linux,stm32,arm開發(fā),運維,java,物聯(lián)網(wǎng)

OneNET

中文頁 | English

1、介紹

OneNET 平臺是中國移動基于物聯(lián)網(wǎng)產(chǎn)業(yè)打造的生態(tài)平臺,具有高并發(fā)可用、多協(xié)議接入、豐富 API 支持、數(shù)據(jù)安全存儲、快速應(yīng)用孵化等特點,同時,OneNET 平臺還提供全方位支撐,加速用戶產(chǎn)品的開發(fā)速度。

OneNET 軟件包是 RT-Thread 針對 OneNET 平臺連接做的的適配,通過這個軟件包,可以讓設(shè)備在 RT-Thread 上非常方便的連接 OneNet 平臺,完成數(shù)據(jù)的發(fā)送、接收、設(shè)備的注冊和控制等功能。

軟件包具有以下優(yōu)點:

  • 斷線重連
  • 自動注冊
  • 自定義響應(yīng)函數(shù)
  • 自定義 topic 和 topic 對應(yīng)的回調(diào)函數(shù)
  • 上傳二進制數(shù)據(jù)

更多介紹請查看詳細介紹

1.1 目錄結(jié)構(gòu)

OneNET
│   README.md                       // 軟件包使用說明
│   SConscript                      // RT-Thread 默認的構(gòu)建腳本
├───docs 
│   └───figures                     // 文檔使用圖片
│   │   api.md                      // API 使用說明
│   │   introduction.md             // 軟件包詳細介紹
│   │   principle.md                // 實現(xiàn)原理
│   │   README.md                   // 文檔結(jié)構(gòu)說明
│   │   samples.md                  // 軟件包示例
│   │   user-guide.md               // 使用說明
│   │   port.md                     // 移植說明文檔
│   └───version.md                  // 版本
├───ports                           // 移植文件                 
│   └───onenet_port.c               // 移植文件模板
├───samples                         // 示例代碼
│   └───onenet_sample.c             // 軟件包應(yīng)用示例代碼
├───inc                             // 頭文件
└───src                             // 源文件

1.2 許可證

OneNET package 遵循 GUN GPL 許可,詳見 LICENSE 文件。

1.3 依賴

  • RT_Thread 3.0+
  • paho-mqtt
  • webclient
  • cJSON

2、獲取方式

使用 OneNET package 需要在 RT-Thread 的包管理中選中它,具體路徑如下:

RT-Thread online packages
    IoT - internet of things  --->
        IoT Cloud  --->
            [*] OneNET: China Mobile OneNet cloud SDK for RT-Thread

進入 onenet 軟件包的配置菜單按下圖所示配置,里面的信息依據(jù)自己的產(chǎn)品和設(shè)備的實際情況填寫

--- OneNET: China Mobile OneNet cloud SDK for RT-Thread                            
    [ ]   Enable OneNET sample                                                  
    [*]   Enable support MQTT protocol                                                 
    [ ]   Enable OneNET automatic register device (NEW)                             
    (35936966) device id                                                             
    (201807171718) auth info
    (H3ak5Bbl0NxpW3QVVe33InnPxOg=) api key                                              
    (156418) product id                                                                 
    (dVZ=ZjVJvGjXIUDsbropzg1a8Dw=) master/product apikey (NEW)                       
        version (latest)  --->

Enable OneNET sample :開啟 OneNET 示例代碼

Enable support MQTT protocol :開啟 MQTT 協(xié)議連接 OneNET 支持

Enable OneNET automatic register device :開啟 OneNET 自動注冊設(shè)備功能

device id :配置云端創(chuàng)建設(shè)備時獲取的 設(shè)備ID

auth info :配置云端創(chuàng)建產(chǎn)品時 用戶自定義的鑒權(quán)信息 (每個產(chǎn)品的每個設(shè)備唯一)

api key :配置云端創(chuàng)建設(shè)備時獲取的 APIkey

product id :配置云端創(chuàng)建產(chǎn)品時獲取的 產(chǎn)品ID

master/product apikey :配置云端創(chuàng)建產(chǎn)品時獲取的 產(chǎn)品APIKey

配置完成后讓 RT-Thread 的包管理器自動更新,或者使用 pkgs --update 命令更新包到 BSP 中。

3、使用 OneNET 軟件包

  • 詳細的示例介紹,請參考 示例文檔 。

  • 如何從零開始使用,請參考 用戶手冊。

  • 完整的 API 文檔,請參考 API 手冊。

  • OneNET 軟件包工作原理,請參考 工作原理 。

  • OneNET 軟件包移植,請參考 移植手冊 。

  • 更多詳細介紹文檔位于 /docs 文件夾下,使用軟件包進行開發(fā)前請務(wù)必查看。

4、注意事項

  • 未啟用自動注冊功能,在 menuconfig 選項中配置的 device id、api key、product id、auth info 等信息需要和 OneNET 云端新建產(chǎn)品和新建設(shè)備時獲取的信息一致。
  • 啟用自動注冊功能后,需要閱讀移植手冊并完成移植工作。
  • 初始化 OneNET package 之前需要設(shè)備聯(lián)網(wǎng)成功。

示例代碼

…\bsp\stm32\stm32l452-st-nucleo\board\board.c文章來源地址http://www.zghlxwxcb.cn/news/detail-824061.html

/*
 * File      : onenet_http.c
 * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Change Logs:
 * Date           Author       Notes
 * 2018-04-24     chenyong     first version
 */
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>

#include <cJSON_util.h>
#include <webclient.h>

#include <onenet.h>

#define DBG_ENABLE
#define DBG_COLOR
#define DBG_SECTION_NAME    "onenet.http"
#if ONENET_DEBUG
#define DBG_LEVEL           DBG_LOG
#else
#define DBG_LEVEL           DBG_INFO
#endif /* ONENET_DEBUG */

#include <rtdbg.h>

#define ONENET_SEND_DATA_LEN           1024
#define ONENET_HEAD_DATA_LEN           256
#define ONENET_CON_URI_LEN             256
#define ONENET_RECV_RESP_LEN           1024
#define ONENET_TIME_BUF_LEN            24
#define ONENET_HTTP_HEAD_LEN           1024

#if WEBCLIENT_SW_VERSION_NUM < 0x20000
#error "Please upgrade the webclient version "
#endif

#define WEBCLIENT_HEADER_ADD(session, fmt, ...)                                                         \
    do                                                                                                  \
    {                                                                                                   \
        if (webclient_header_fields_add(session, fmt, ##__VA_ARGS__) < 0)                               \
        {                                                                                               \
            LOG_E("webclient add header failed!");                                                      \
            goto __exit;                                                                                \
        }                                                                                               \
    } while(0);                                                                                         \

extern struct rt_onenet_info onenet_info;

static rt_err_t onenet_upload_data(char *send_buffer)
{
    struct webclient_session *session = RT_NULL;
    char *buffer = send_buffer;
    char *URI = RT_NULL;
    rt_err_t result = RT_EOK;

    RT_ASSERT(send_buffer);

    URI = ONENET_CALLOC(1, ONENET_CON_URI_LEN);
    if (URI == RT_NULL)
    {
        LOG_E("OneNet Send data failed! No memory for URI buffer!");
        result = -RT_ENOMEM;
        goto __exit;
    }

    rt_snprintf(URI, ONENET_CON_URI_LEN, "http://api.heclouds.com/devices/%s/datapoints?type=3", onenet_info.device_id);

    session = webclient_session_create(ONENET_HTTP_HEAD_LEN);
    if (session == RT_NULL)
    {
        result = -RT_ERROR;
        goto __exit;
    }

    WEBCLIENT_HEADER_ADD(session, "api-key: %s\r\n", onenet_info.api_key);
    WEBCLIENT_HEADER_ADD(session, "Content-Length: %d\r\n", strlen(buffer));
    WEBCLIENT_HEADER_ADD(session, "Content-Type: application/octet-stream\r\n");

    if (webclient_post(session, URI, buffer, strlen(buffer)) != 200)
    {
        result = -RT_ERROR;
        goto __exit;
    }

    LOG_D("buffer : %.*s", strlen(buffer), buffer);

__exit:
    if (session)
    {
        webclient_close(session);
    }
    if (URI)
    {
        ONENET_FREE(URI);
    }

    return result;
}


static rt_err_t onenet_get_string_data(const char *ds_name, const char *str, char **out_buff)
{
    rt_err_t result = RT_EOK;
    cJSON *root = RT_NULL;

    RT_ASSERT(ds_name);
    RT_ASSERT(str);
    RT_ASSERT(out_buff);

    root = cJSON_CreateObject();
    if (!root)
    {
        LOG_E("onenet publish string data failed! cJSON create object error return NULL!");
        return -RT_ENOMEM;
    }

    cJSON_AddStringToObject(root, ds_name, str);

    /* render a cJSON structure to buffer */
    *out_buff = cJSON_PrintUnformatted(root);
    if (!(*out_buff))
    {
        LOG_E("onenet publish string data failed! cJSON print unformatted error return NULL!");
        result = -RT_ENOMEM;
        goto __exit;
    }

__exit:
    if (root)
    {
        cJSON_Delete(root);
    }

    return result;
}

static rt_err_t onenet_get_digit_data(const char *ds_name, const double digit, char **out_buff)
{
    rt_err_t result = RT_EOK;
    cJSON *root = RT_NULL;

    RT_ASSERT(ds_name);
    RT_ASSERT(out_buff);

    root = cJSON_CreateObject();
    if (!root)
    {
        LOG_E("onenet publish digit data failed! cJSON create object error return NULL!");
        return -RT_ENOMEM;
    }

    cJSON_AddNumberToObject(root, ds_name, digit);

    /* render a cJSON structure to buffer */
    *out_buff = cJSON_PrintUnformatted(root);
    if (!(*out_buff))
    {
        LOG_E("onenet publish digit data failed! cJSON print unformatted error return NULL!");
        result = -RT_ENOMEM;
        goto __exit;
    }

__exit:
    if (root)
    {
        cJSON_Delete(root);
    }

    return result;
}

/**
 * upload digit data to OneNET cloud.
 *
 * @param   ds_name     datastream name
 * @param   digit       digit data
 *
 * @return  0 : upload data success
 *         -5 : no memory
 */
rt_err_t onenet_http_upload_digit(const char *ds_name, const double digit)
{
    char *send_buffer = RT_NULL;
    rt_err_t result = RT_EOK;

    RT_ASSERT(ds_name);

    /* get JSON format data */
    result = onenet_get_digit_data(ds_name, digit, &send_buffer);
    if (result < 0)
    {
        goto __exit;
    }

    /* send data to cloud by HTTP */
    result = onenet_upload_data(send_buffer);
    if (result < 0)
    {
        goto __exit;
    }

__exit:
    if (send_buffer)
    {
        cJSON_free(send_buffer);
    }

    return result;
}

/**
 * upload string data to OneNET cloud.
 *
 * @param   ds_name     datastream name
 * @param   str         string data
 *
 * @return  0 : upload data success
 *         -5 : no memory
 */
rt_err_t onenet_http_upload_string(const char *ds_name, const char *str)
{
    char *send_buffer = RT_NULL;
    rt_err_t result = RT_EOK;

    RT_ASSERT(ds_name);
    RT_ASSERT(str);

    /* get JSON format data */
    result = onenet_get_string_data(ds_name, str, &send_buffer);
    if (result < 0)
    {
        goto __exit;
    }

    /* send data to cloud by HTTP */
    result = onenet_upload_data(send_buffer);
    if (result < 0)
    {
        goto __exit;
    }

__exit:
    if (send_buffer)
    {
        cJSON_free(send_buffer);
    }

    return result;
}

#ifdef ONENET_USING_AUTO_REGISTER
static rt_err_t response_register_handlers(const unsigned char *rec_buf, const size_t length)
{
    cJSON *root = RT_NULL;
    cJSON *item = RT_NULL;
    cJSON *itemid = RT_NULL;
    cJSON *itemapikey = RT_NULL;

    RT_ASSERT(rec_buf);

    LOG_D("response is %.*s", length, rec_buf);

    root = cJSON_Parse((char *)rec_buf);
    if (!root)
    {
        LOG_E("onenet register device failed! cJSON Parse data error return NULL!");
        return -RT_ENOMEM;
    }

    item = cJSON_GetObjectItem(root, "errno");
    if (item->valueint == 0)
    {
        itemid = cJSON_GetObjectItem(root->child->next, "device_id");
        itemapikey = cJSON_GetObjectItem(root->child->next, "key");

        onenet_port_save_device_info(itemid->valuestring, itemapikey->valuestring);
    }
    else
    {
        LOG_E("onenet register device failed! errno is %d", item->valueint);
        return -RT_ERROR;
    }

    return RT_EOK;

}



#endif /* ONENET_USING_AUTO_REGISTER */







維護人:

  • 華為奮斗者精神, 郵箱:1992152446@qq.com

到了這里,關(guān)于RT-Thread 軟件包-IoT-OneNET①的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • RT-Thread 軟件包-物聯(lián)網(wǎng)-網(wǎng)絡(luò)工具集NetUtils使用指南①

    RT-Thread 軟件包-物聯(lián)網(wǎng)-網(wǎng)絡(luò)工具集NetUtils使用指南①

    本文介紹 RT-Thread NetUtils 的使用方法,幫助開發(fā)者更好地使用 RT-Thread NetUtils 組件來解決網(wǎng)絡(luò)開發(fā)過程中遇到的問題。 簡介 在進行網(wǎng)絡(luò)相關(guān)的產(chǎn)品開發(fā)和調(diào)試時,一些好用的小工具往往能取到事半功倍的效果。 RT-Thread NetUtils 組件基于此應(yīng)用場景,開發(fā)和封裝了一系列簡潔好

    2024年02月20日
    瀏覽(25)
  • RT-Thread 軟件包-PikaScript用戶手冊-STM32模塊API文檔①

    RT-Thread 軟件包-PikaScript用戶手冊-STM32模塊API文檔①

    RT-Thread軟件包中的PikaScript用戶手冊針對STM32模塊提供了API文檔。STM32模塊是一個為基于STM32微控制器的RT-Thread系統(tǒng)提供支持的功能模塊,它提供了對STM32硬件資源的訪問和控制。 在PikaScript用戶手冊中,針對STM32模塊的API文檔主要包括以下幾個部分: GPIO控制:STM32模塊提供了一

    2024年02月02日
    瀏覽(34)
  • RT-Thread STM32L475 IoT Discovery kit BSP說明①

    RT-Thread STM32L475 IoT Discovery kit BSP說明①

    本文檔為 RT-Thread 開發(fā)團隊為 STM32L475 IoT Discovery kit開發(fā)板提供的 BSP (板級支持包) 說明。 主要內(nèi)容如下: 開發(fā)板資源介紹 BSP 快速上手 進階使用方法 通過閱讀快速上手章節(jié)開發(fā)者可以快速地上手該 BSP,將 RT-Thread 運行在開發(fā)板上。在進階使用指南章節(jié),將會介紹更多高級功

    2024年02月02日
    瀏覽(40)
  • RT-Thread 1. GD32移植RT-Thread Nano

    RT-Thread 1. GD32移植RT-Thread Nano

    1. RT-Thread Nano?下載 RT-Thread Nano 是一個極簡版的硬實時內(nèi)核,它是由 C 語言開發(fā),采用面向?qū)ο蟮木幊趟季S,具有良好的代碼風(fēng)格,是一款可裁剪的、搶占式實時多任務(wù)的 RTOS。其內(nèi)存資源占用極小,功能包括任務(wù)處理、軟件定時器、信號量、郵箱和實時調(diào)度等相對完整的實

    2024年02月05日
    瀏覽(29)
  • RT-Thread 9. VS2012下仿真RT-Thread 和LVGL

    RT-Thread 9. VS2012下仿真RT-Thread 和LVGL

    1. 在ENV中添加組件 2. 下載組件 3. 生成代碼 4. 打開代碼 雙擊project.vcxproj 編譯 5. 運行

    2024年02月06日
    瀏覽(24)
  • RT-Thread 7. RT-Thread Studio ENV修改MCU型號

    RT-Thread 7. RT-Thread Studio ENV修改MCU型號

    1. 修改MCU型號 2.在ENV界面輸入 3. dist下為更新后完整源代碼 4.導(dǎo)入RT-Thread Studio 發(fā)現(xiàn)GD32F330已經(jīng)生效了。 5. 自己編寫startup_gd32f3x0.S,準(zhǔn)確性待驗證

    2024年02月06日
    瀏覽(27)
  • 【STM32&RT-Thread零基礎(chǔ)入門】 2. 新建RT-Thread項目

    【STM32&RT-Thread零基礎(chǔ)入門】 2. 新建RT-Thread項目

    硬件:STM32F103ZET6、ST-LINK、usb轉(zhuǎn)串口工具 RT-Thread的全稱是Real Time Thread,顧名思義,它是一個嵌入式實時多線程操作系統(tǒng)。相較于 Linux 操作系統(tǒng),RT-Thread 體積小,成本低,功耗低、啟動快速,除此之外 RT-Thread 還具有實時性高、占用資源小等特點,非常適用于各種資源受限(

    2024年02月13日
    瀏覽(24)
  • 使用RT-Thread Studio搭配STM32CubeMX新建RT-Thread項目

    使用RT-Thread Studio搭配STM32CubeMX新建RT-Thread項目

    STM32CubeMX下載 RT-Thread Studio下載 安裝好RT-Thread Studio后,先打開RT-Thread SDK管理器確認有沒有自己MCU需要的SDK包,直接安裝好之后里面是有STM32F1系列的SDK包,其他的需要自己安裝。 之后點擊文件→新建→RT-Thread項目,根據(jù)自己需要配置好后點擊完成就會生成RT-Thread項目。 新建項

    2024年02月11日
    瀏覽(20)
  • 【STM32&RT-Thread零基礎(chǔ)入門】8. 基于 CubeMX 移植 RT-Thread Nano

    【STM32&RT-Thread零基礎(chǔ)入門】8. 基于 CubeMX 移植 RT-Thread Nano

    硬件:STM32F103ZET6、ST-LINK、usb轉(zhuǎn)串口工具、4個LED燈、1個蜂鳴器、4個1k電阻、2個按鍵、面包板、杜邦線 利用RT_Thread操作系統(tǒng)實現(xiàn)三種不同的LED等閃爍 提示:以下是本篇文章正文內(nèi)容,下面案例可供參考 cubemx配置參考教程: 基于 CubeMX 移植 RT-Thread Nano 后面程序所需的引腳 RT

    2024年02月09日
    瀏覽(30)
  • 【RT-Thread】使用RT-Thread Studio 配置BootLoader及App實現(xiàn)OTA功能

    【RT-Thread】使用RT-Thread Studio 配置BootLoader及App實現(xiàn)OTA功能

    由于項目需要實現(xiàn)OTA功能學(xué)習(xí)了一下具體實現(xiàn)方法,以備后期查看,有問題的地方隨時指正修改 1.什么是OTA OTA是“over-the-air”的縮寫,是一種無線技術(shù),用于在不需要接觸設(shè)備的情況下向移動設(shè)備或物聯(lián)網(wǎng)設(shè)備提供更新、補丁或新版本的軟件。OTA更新通常通過無線網(wǎng)絡(luò)(如

    2024年02月09日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包