mirror of
https://github.com/pine64/bl_iot_sdk.git
synced 2024-10-06 06:50:19 +00:00
commit
ad8305fb04
32
customer_app/bl602_http_ota/Makefile
Normal file
32
customer_app/bl602_http_ota/Makefile
Normal file
@ -0,0 +1,32 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := bl602_http_ota
|
||||
PROJECT_PATH := $(abspath .)
|
||||
PROJECT_BOARD := evb
|
||||
export PROJECT_PATH PROJECT_BOARD
|
||||
#CONFIG_TOOLPREFIX :=
|
||||
|
||||
-include ./proj_config.mk
|
||||
|
||||
ifeq ($(origin BL60X_SDK_PATH), undefined)
|
||||
BL60X_SDK_PATH_GUESS ?= $(shell pwd)
|
||||
BL60X_SDK_PATH ?= $(BL60X_SDK_PATH_GUESS)/../..
|
||||
$(info ****** Please SET BL60X_SDK_PATH ******)
|
||||
$(info ****** Trying SDK PATH [$(BL60X_SDK_PATH)])
|
||||
endif
|
||||
|
||||
COMPONENTS_NETWORK := sntp dns_server
|
||||
COMPONENTS_BLSYS := bltime blfdt blmtd blota bloop loopadc looprt loopset
|
||||
COMPONENTS_VFS := romfs
|
||||
|
||||
INCLUDE_COMPONENTS += freertos_riscv_ram bl602 bl602_std bl602_wifi bl602_wifidrv hal_drv lwip lwip_dhcpd mbedtls vfs yloop utils cli aws-iot httpc netutils blog blog_testc
|
||||
INCLUDE_COMPONENTS += easyflash4
|
||||
INCLUDE_COMPONENTS += $(COMPONENTS_NETWORK)
|
||||
INCLUDE_COMPONENTS += $(COMPONENTS_BLSYS)
|
||||
INCLUDE_COMPONENTS += $(COMPONENTS_VFS)
|
||||
INCLUDE_COMPONENTS += $(PROJECT_NAME)
|
||||
include $(BL60X_SDK_PATH)/make_scripts_riscv/project.mk
|
||||
|
11
customer_app/bl602_http_ota/README.md
Normal file
11
customer_app/bl602_http_ota/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# http ota demo
|
||||
|
||||
### Build http server:Port :8080 , OTA firmware:FW_OTA.bin.ota
|
||||
|
||||
![ota_server](ota_server.jpg)
|
||||
|
||||
|
||||
|
||||
### Please use wifi command to connect your network, e.g. "wifi_sta_connect BouffaloLab 123456".
|
||||
|
||||
### Use http ota command to download your ota firmware, e.g. "ota_http_cmd 10.0.0.55"
|
433
customer_app/bl602_http_ota/bl602_http_ota/aws_iot_main.c
Normal file
433
customer_app/bl602_http_ota/bl602_http_ota/aws_iot_main.c
Normal file
@ -0,0 +1,433 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Bouffalolab.
|
||||
*
|
||||
* This file is part of
|
||||
* *** Bouffalolab Software Dev Kit ***
|
||||
* (see www.bouffalolab.com).
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#include <vfs.h>
|
||||
#include <fs/vfs_romfs.h>
|
||||
|
||||
#include "aws_iot_config.h"
|
||||
#include "aws_iot_log.h"
|
||||
#include "aws_iot_version.h"
|
||||
#include "aws_iot_mqtt_client_interface.h"
|
||||
#include "aws_iot_shadow_interface.h"
|
||||
|
||||
#if 0
|
||||
#define USR_AWS_IOT_ROOT_CA_FILENAME "/romfs/aws/root-CA.crt" ///< Root CA file name
|
||||
#define USR_AWS_IOT_CERTIFICATE_FILENAME "/romfs/aws/certificate.pem.crt" ///< device signed certificate file name
|
||||
#define USR_AWS_IOT_PRIVATE_KEY_FILENAME "/romfs/aws/private.pem.key" ///< Device private key filename
|
||||
#else
|
||||
#define USR_AWS_IOT_ROOT_CA_FILENAME \
|
||||
"-----BEGIN CERTIFICATE-----\r\n"\
|
||||
"MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\r\n"\
|
||||
"ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\r\n"\
|
||||
"b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\r\n"\
|
||||
"MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbj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n"\
|
||||
"-----END CERTIFICATE-----\r\n"
|
||||
|
||||
#define USR_AWS_IOT_CERTIFICATE_FILENAME \
|
||||
"-----BEGIN CERTIFICATE-----\r\n"\
|
||||
"MIIDWjCCAkKgAwIBAgIVAOosWE2Km3IxrIwFACK/p1K1hvclMA0GCSqGSIb3DQEB\r\n"\
|
||||
"CwUAME0xSzBJBgNVBAsMQkFtYXpvbiBXZWIgU2VydmljZXMgTz1BbWF6b24uY29t\r\n"\
|
||||
"IEluYy4gTD1TZWF0dGxlIFNUPVdhc2hpbmd0b24gQz1VUzAeFw0xOTA5MDQwNjUw\r\n"\
|
||||
"NTFaFw00OTEyMzEyMzU5NTlaMB4xHDAaBgNVBAMME0FXUyBJb1QgQ2VydGlmaWNh\r\n"\
|
||||
"dGUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDOLZXvbTzYCvzEhyxP\r\n"\
|
||||
"GtF8chZ+r3FZszUdqicDnUqIcKAZiiUC2P/errXnaK/eEye2QUSZmUDpn1xybde4\r\n"\
|
||||
"eG1Kz8BvSnp6UYuoF1hPnLQvnm02ILwANcdjScql6CpYIwuGNvCxP1re+iOnOx7V\r\n"\
|
||||
"kFP02d0w36voNMZHyK755IjjWz5PSEIzXx6RCP/wqkJlz+oZvIrDZZ1dXa5X3ffV\r\n"\
|
||||
"bftYCPj2gDW8AohWYMapDJpRfEdo6g6NkP4VOPS+nZ9Fp9rY6BZqJR6m4otjdMna\r\n"\
|
||||
"I7p3FY5wqOdcF3DPXYMHR0j5SjtDLIeNpX8AP6ekpZsO9k1/VLSK+wxXIHltsYW/\r\n"\
|
||||
"lQtzAgMBAAGjYDBeMB8GA1UdIwQYMBaAFLcyZBzcJOBSL0d+yMxZh3trcG7rMB0G\r\n"\
|
||||
"A1UdDgQWBBSgGPuINfSBCTZxtcV3epnSuxPdlTAMBgNVHRMBAf8EAjAAMA4GA1Ud\r\n"\
|
||||
"DwEB/wQEAwIHgDANBgkqhkiG9w0BAQsF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rQlw6MzpI9d\r\n"\
|
||||
"SpQZHT/IKgCmhhoz+r8MXyaYkTVbaUyYf90ntsPUO8JfbkBOaSge7PwMBFTm3Za+\r\n"\
|
||||
"oADSY5KTAoGBAK3f+otZPfZA1LTpWYbOpCl10Ci/R/xU13Ak7omahkpXX/dMHt3s\r\n"\
|
||||
"d0fpsuduQwrQOGJLEZG/Z1zeNSp8QtGKH/RH57tWJBFR1XWEJ9kyH/FPVaighzPU\r\n"\
|
||||
"T9VIJw2g//PLTT7yV/D9HmiNMj0hQYkTP3bGKvaiOrhC7a0Us4KhMGFc\r\n"\
|
||||
"-----END RSA PRIVATE KEY-----\r\n"
|
||||
#endif
|
||||
#define USR_AWS_IOT_CONFIG_FILE "/romfs/aws/config" ///< Device private key filename
|
||||
#define AWS_IOT_MQTT_HOST "ap3im43fimllm-ats.iot.us-east-1.amazonaws.com"
|
||||
#define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S
|
||||
#define AWS_IOT_MQTT_CLIENT_ID "bl60xDevRjwang"
|
||||
#define AWS_IOT_MY_THING_NAME "bl60xDevRjwang"
|
||||
|
||||
#define ROOMTEMPERATURE_UPPERLIMIT 32.0f
|
||||
#define ROOMTEMPERATURE_LOWERLIMIT 25.0f
|
||||
#define STARTING_ROOMTEMPERATURE ROOMTEMPERATURE_LOWERLIMIT
|
||||
|
||||
#define MAX_LENGTH_OF_UPDATE_JSON_BUFFER 200
|
||||
static void simulateRoomTemperature(float *pRoomTemperature) {
|
||||
static float deltaChange;
|
||||
|
||||
if(*pRoomTemperature >= ROOMTEMPERATURE_UPPERLIMIT) {
|
||||
deltaChange = -0.5f;
|
||||
} else if(*pRoomTemperature <= ROOMTEMPERATURE_LOWERLIMIT) {
|
||||
deltaChange = 0.5f;
|
||||
}
|
||||
|
||||
*pRoomTemperature += deltaChange;
|
||||
}
|
||||
|
||||
static bool shadowUpdateInProgress;
|
||||
|
||||
void ShadowUpdateStatusCallback(const char *pThingName, ShadowActions_t action, Shadow_Ack_Status_t status,
|
||||
const char *pReceivedJsonDocument, void *pContextData) {
|
||||
IOT_UNUSED(pThingName);
|
||||
IOT_UNUSED(action);
|
||||
IOT_UNUSED(pReceivedJsonDocument);
|
||||
IOT_UNUSED(pContextData);
|
||||
|
||||
shadowUpdateInProgress = false;
|
||||
|
||||
if(SHADOW_ACK_TIMEOUT == status) {
|
||||
printf("Update timed out\r\n");
|
||||
} else if(SHADOW_ACK_REJECTED == status) {
|
||||
printf("Update rejected\r\n");
|
||||
} else if(SHADOW_ACK_ACCEPTED == status) {
|
||||
printf("Update accepted\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
void windowActuate_Callback(const char *pJsonString, uint32_t JsonStringDataLen, jsonStruct_t *pContext) {
|
||||
IOT_UNUSED(pJsonString);
|
||||
IOT_UNUSED(JsonStringDataLen);
|
||||
|
||||
if(pContext != NULL) {
|
||||
printf("Delta - Window state changed to %d\r\n", *(bool *) (pContext->pData));
|
||||
}
|
||||
}
|
||||
|
||||
static int _update_mqtt_config(ShadowInitParameters_t *sp, ShadowConnectParameters_t *scp)
|
||||
{
|
||||
int fd, len;
|
||||
char *c_ptr;
|
||||
romfs_filebuf_t filebuf;
|
||||
char port[8];
|
||||
|
||||
fd = aos_open(USR_AWS_IOT_CONFIG_FILE, 0);
|
||||
if (fd < 0) {
|
||||
printf("Open config file %s failed\r\n", USR_AWS_IOT_CONFIG_FILE);
|
||||
return -1;
|
||||
}
|
||||
aos_ioctl(fd, IOCTL_ROMFS_GET_FILEBUF, (long unsigned int)&filebuf);
|
||||
c_ptr = filebuf.buf;
|
||||
|
||||
/*get host URL*/
|
||||
len = 0;
|
||||
while (*c_ptr != '\n' && *c_ptr != '\r') {
|
||||
c_ptr++;
|
||||
len++;
|
||||
}
|
||||
printf("URL len is %d,", len);
|
||||
sp->pHost = pvPortMalloc(len);
|
||||
if (NULL == sp->pHost) {
|
||||
//TODO use ASSERT here
|
||||
printf("NULL pHost %d\r\n", __LINE__);
|
||||
while (1) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
memcpy(sp->pHost, c_ptr - len, len);
|
||||
sp->pHost[len] = '\0';
|
||||
printf(" URL:%s\r\n", sp->pHost);
|
||||
|
||||
/*get host port*/
|
||||
while (*c_ptr == '\n' || *c_ptr == '\r') {
|
||||
c_ptr++;
|
||||
}
|
||||
len = 0;
|
||||
while (*c_ptr != '\n' && *c_ptr != '\r') {
|
||||
c_ptr++;
|
||||
len++;
|
||||
}
|
||||
printf("port len is %d", len);
|
||||
if (len > 5) {
|
||||
printf("Too long port\r\n");
|
||||
while (1) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
memcpy(port, c_ptr - len, len);
|
||||
port[len] = '\0';
|
||||
sp->port = atoi(port);
|
||||
printf(", port is %d\r\n", sp->port);
|
||||
|
||||
sp->pClientCRT = USR_AWS_IOT_CERTIFICATE_FILENAME;
|
||||
sp->pClientKey = USR_AWS_IOT_PRIVATE_KEY_FILENAME;
|
||||
sp->pRootCA = USR_AWS_IOT_ROOT_CA_FILENAME;
|
||||
sp->enableAutoReconnect = false;
|
||||
sp->disconnectHandler = NULL;
|
||||
|
||||
/*get thing id*/
|
||||
while (*c_ptr == '\n' || *c_ptr == '\r') {
|
||||
c_ptr++;
|
||||
}
|
||||
len = 0;
|
||||
while (*c_ptr != '\n' && *c_ptr != '\r') {
|
||||
c_ptr++;
|
||||
len++;
|
||||
}
|
||||
printf("thing id len is %d", len);
|
||||
scp->pMqttClientId = pvPortMalloc(len);
|
||||
if (NULL == scp->pMqttClientId) {
|
||||
//TODO use ASSERT here
|
||||
printf("NULL pMqttClientId %d\r\n", __LINE__);
|
||||
while (1) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
memcpy((void*)scp->pMqttClientId, c_ptr - len, len);
|
||||
((char*)scp->pMqttClientId)[len] = '\0';
|
||||
printf(", THING ID is %s\r\n", scp->pMqttClientId);
|
||||
scp->mqttClientIdLen = strlen(scp->pMqttClientId);
|
||||
|
||||
/*get thing name*/
|
||||
while (*c_ptr == '\n' || *c_ptr == '\r') {
|
||||
c_ptr++;
|
||||
}
|
||||
len = 0;
|
||||
while (*c_ptr != '\n' && *c_ptr != '\r') {
|
||||
c_ptr++;
|
||||
len++;
|
||||
}
|
||||
printf("thing name len is %d", len);
|
||||
scp->pMyThingName = pvPortMalloc(len);
|
||||
if (NULL == scp->pMyThingName) {
|
||||
//TODO use ASSERT here
|
||||
printf("NULL pMyThingName %d\r\n", __LINE__);
|
||||
while (1) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
memcpy((void*)scp->pMyThingName, c_ptr - len, len);
|
||||
((char*)scp->pMyThingName)[len] = '\0';
|
||||
printf(", THING name is %s\r\n", scp->pMyThingName);
|
||||
|
||||
aos_close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _update_mqtt_config_default(ShadowInitParameters_t *sp, ShadowConnectParameters_t *scp)
|
||||
{
|
||||
sp->pHost = AWS_IOT_MQTT_HOST;
|
||||
printf(" URL:%s\r\n", sp->pHost);
|
||||
|
||||
sp->port = AWS_IOT_MQTT_PORT;
|
||||
printf(", port is %d\r\n", sp->port);
|
||||
|
||||
sp->pClientCRT = USR_AWS_IOT_CERTIFICATE_FILENAME;
|
||||
sp->pClientKey = USR_AWS_IOT_PRIVATE_KEY_FILENAME;
|
||||
sp->pRootCA = USR_AWS_IOT_ROOT_CA_FILENAME;
|
||||
sp->enableAutoReconnect = false;
|
||||
sp->disconnectHandler = NULL;
|
||||
|
||||
scp->pMqttClientId = AWS_IOT_MQTT_CLIENT_ID;
|
||||
printf(", THING ID is %s\r\n", scp->pMqttClientId);
|
||||
scp->mqttClientIdLen = strlen(scp->pMqttClientId);
|
||||
|
||||
printf("thing name len is %d", strlen(AWS_IOT_MY_THING_NAME));
|
||||
scp->pMyThingName = AWS_IOT_MY_THING_NAME;
|
||||
printf(", THING name is %s\r\n", scp->pMyThingName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void aws_main_entry(void *param)
|
||||
{
|
||||
IoT_Error_t rc = FAILURE;
|
||||
ShadowInitParameters_t sp = ShadowInitParametersDefault;
|
||||
ShadowConnectParameters_t scp = ShadowConnectParametersDefault;
|
||||
|
||||
char JsonDocumentBuffer[MAX_LENGTH_OF_UPDATE_JSON_BUFFER];
|
||||
size_t sizeOfJsonDocumentBuffer = sizeof(JsonDocumentBuffer) / sizeof(JsonDocumentBuffer[0]);
|
||||
float temperature = 0.0;
|
||||
|
||||
bool windowOpen = false;
|
||||
jsonStruct_t windowActuator;
|
||||
windowActuator.cb = windowActuate_Callback;
|
||||
windowActuator.pData = &windowOpen;
|
||||
windowActuator.pKey = "windowOpen";
|
||||
windowActuator.type = SHADOW_JSON_BOOL;
|
||||
windowActuator.dataLength = sizeof(bool);
|
||||
|
||||
jsonStruct_t temperatureHandler;
|
||||
temperatureHandler.cb = NULL;
|
||||
temperatureHandler.pKey = "temperature";
|
||||
temperatureHandler.pData = &temperature;
|
||||
temperatureHandler.type = SHADOW_JSON_FLOAT;
|
||||
temperatureHandler.dataLength = sizeof(float);
|
||||
|
||||
printf("AWS IoT SDK Version %d.%d.%d-%s\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG);
|
||||
|
||||
// initialize the mqtt client
|
||||
AWS_IoT_Client mqttClient;
|
||||
|
||||
if (_update_mqtt_config(&sp, &scp)) {
|
||||
_update_mqtt_config_default(&sp, &scp);
|
||||
}
|
||||
printf("Shadow Init\r\n");
|
||||
rc = aws_iot_shadow_init(&mqttClient, &sp);
|
||||
if(SUCCESS != rc) {
|
||||
printf("aws_iot_shadow_init returned error %d, aborting...\r\n", rc);
|
||||
while (1) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Shadow Connect\r\n");
|
||||
rc = aws_iot_shadow_connect(&mqttClient, &scp);
|
||||
if(SUCCESS != rc) {
|
||||
printf("aws_iot_shadow_connect returned error %d, aborting...\r\n", rc);
|
||||
while (1) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable Auto Reconnect functionality. Minimum and Maximum time of Exponential backoff are set in aws_iot_config.h
|
||||
* #AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL
|
||||
* #AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL
|
||||
*/
|
||||
rc = aws_iot_shadow_set_autoreconnect_status(&mqttClient, true);
|
||||
if(SUCCESS != rc) {
|
||||
printf("Unable to set Auto Reconnect to true - %d, aborting...\r\n", rc);
|
||||
while (1) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
rc = aws_iot_shadow_register_delta(&mqttClient, &windowActuator);
|
||||
|
||||
if(SUCCESS != rc) {
|
||||
printf("Shadow Register Delta Error\r\n");
|
||||
while (1) {
|
||||
vTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
temperature = STARTING_ROOMTEMPERATURE;
|
||||
|
||||
// loop and publish a change in temperature
|
||||
while(NETWORK_ATTEMPTING_RECONNECT == rc || NETWORK_RECONNECTED == rc || SUCCESS == rc) {
|
||||
rc = aws_iot_shadow_yield(&mqttClient, 200);
|
||||
if(NETWORK_ATTEMPTING_RECONNECT == rc || shadowUpdateInProgress) {
|
||||
rc = aws_iot_shadow_yield(&mqttClient, 1000);
|
||||
// If the client is attempting to reconnect, or already waiting on a shadow update,
|
||||
// we will skip the rest of the loop.
|
||||
continue;
|
||||
}
|
||||
printf("=======================================================================================\r\n");
|
||||
printf("On Device: window state %s\r\n", windowOpen ? "true" : "false");
|
||||
simulateRoomTemperature(&temperature);
|
||||
|
||||
rc = aws_iot_shadow_init_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
|
||||
if(SUCCESS == rc) {
|
||||
rc = aws_iot_shadow_add_reported(JsonDocumentBuffer, sizeOfJsonDocumentBuffer, 2, &temperatureHandler,
|
||||
&windowActuator);
|
||||
if(SUCCESS == rc) {
|
||||
rc = aws_iot_finalize_json_document(JsonDocumentBuffer, sizeOfJsonDocumentBuffer);
|
||||
if(SUCCESS == rc) {
|
||||
printf("Update Shadow: %s\r\n", JsonDocumentBuffer);
|
||||
rc = aws_iot_shadow_update(&mqttClient, scp.pMyThingName, JsonDocumentBuffer,
|
||||
ShadowUpdateStatusCallback, NULL, 4, true);
|
||||
shadowUpdateInProgress = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("*****************************************************************************************\r\n");
|
||||
printf("Stack remaining for task '%s' is %ld bytes\r\n", pcTaskGetTaskName(NULL), uxTaskGetStackHighWaterMark(NULL));
|
||||
|
||||
vTaskDelay(1000 / portTICK_RATE_MS);
|
||||
}
|
||||
|
||||
if(SUCCESS != rc) {
|
||||
printf("An error occurred in the loop %d\r\n", rc);
|
||||
}
|
||||
|
||||
printf("Disconnecting\r\n");
|
||||
rc = aws_iot_shadow_disconnect(&mqttClient);
|
||||
|
||||
if(SUCCESS != rc) {
|
||||
printf("Disconnect error %d\r\n", rc);
|
||||
}
|
||||
|
||||
vTaskDelete(NULL);
|
||||
}
|
285
customer_app/bl602_http_ota/bl602_http_ota/bl_http_ota.c
Normal file
285
customer_app/bl602_http_ota/bl602_http_ota/bl_http_ota.c
Normal file
@ -0,0 +1,285 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Bouffalolab.
|
||||
*
|
||||
* This file is part of
|
||||
* *** Bouffalolab Software Dev Kit ***
|
||||
* (see www.bouffalolab.com).
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include <utils_log.h>
|
||||
#include <stdlib.h>
|
||||
#include <wifi_mgmr_ext.h>
|
||||
#include <lwip/ip4_addr.h>
|
||||
#include <http_client.h>
|
||||
#include <utils_sha256.h>
|
||||
#include <hal_boot2.h>
|
||||
#include <bl_mtd.h>
|
||||
#include "bl_http_ota.h"
|
||||
#include <hal_sys.h>
|
||||
#include <semphr.h>
|
||||
#include <cli.h>
|
||||
|
||||
static xSemaphoreHandle otaSema;
|
||||
static ssize_t otaTotalLength = 0;
|
||||
static uint8_t *otaBuffer = NULL;
|
||||
static iot_sha256_context otaCtx;
|
||||
static uint8_t otaSha256Result[32];
|
||||
static uint8_t otaSha256Img[32];
|
||||
static bl_mtd_handle_t otaHandle = NULL;
|
||||
static HALPartition_Entry_Config otaEntry;
|
||||
#define OTA_BUFFER_SIZE 4096
|
||||
typedef struct ota_header {
|
||||
union {
|
||||
struct {
|
||||
uint8_t header[16];
|
||||
|
||||
uint8_t type[4];//RAW XZ
|
||||
uint32_t len;//body len
|
||||
uint8_t pad0[8];
|
||||
|
||||
uint8_t ver_hardware[16];
|
||||
uint8_t ver_software[16];
|
||||
|
||||
uint8_t sha256[32];
|
||||
} s;
|
||||
uint8_t _pad[512];
|
||||
} u;
|
||||
} ota_header_t;
|
||||
#define OTA_HEADER_SIZE (sizeof(ota_header_t))
|
||||
|
||||
static int check_ota_header(ota_header_t *ota_header, uint32_t *ota_len, int *use_xz)
|
||||
{
|
||||
char str[33];//assume max segment size
|
||||
int i;
|
||||
|
||||
memcpy(str, ota_header->u.s.header, sizeof(ota_header->u.s.header));
|
||||
str[sizeof(ota_header->u.s.header)] = '\0';
|
||||
printf("[OTA] [HEADER] ota header is ");
|
||||
printf(str);
|
||||
printf("\r\n");
|
||||
|
||||
memcpy(str, ota_header->u.s.type, sizeof(ota_header->u.s.type));
|
||||
str[sizeof(ota_header->u.s.type)] = '\0';
|
||||
printf("[OTA] [HEADER] file type is ");
|
||||
printf(str);
|
||||
printf("\r\n");
|
||||
if (strstr(str, "XZ")) {
|
||||
*use_xz = 1;
|
||||
} else {
|
||||
*use_xz = 0;
|
||||
}
|
||||
|
||||
memcpy(ota_len, &(ota_header->u.s.len), 4);
|
||||
printf("[OTA] [HEADER] file length (exclude ota header) is %lu\r\n", *ota_len);
|
||||
|
||||
memcpy(str, ota_header->u.s.ver_hardware, sizeof(ota_header->u.s.ver_hardware));
|
||||
str[sizeof(ota_header->u.s.ver_hardware)] = '\0';
|
||||
printf("[OTA] [HEADER] ver_hardware is ");
|
||||
printf(str);
|
||||
printf("\r\n");
|
||||
|
||||
memcpy(str, ota_header->u.s.ver_software, sizeof(ota_header->u.s.ver_software));
|
||||
str[sizeof(ota_header->u.s.ver_software)] = '\0';
|
||||
printf("[OTA] [HEADER] ver_software is ");
|
||||
printf(str);
|
||||
printf("\r\n");
|
||||
|
||||
memcpy(str, ota_header->u.s.sha256, sizeof(ota_header->u.s.sha256));
|
||||
str[sizeof(ota_header->u.s.sha256)] = '\0';
|
||||
printf("[OTA] [HEADER] sha256 is ");
|
||||
for (i = 0; i < sizeof(ota_header->u.s.sha256); i++) {
|
||||
printf("%02X", str[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void cb_httpc_result(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err)
|
||||
{
|
||||
httpc_state_t **req = (httpc_state_t**)arg;
|
||||
|
||||
printf("[HTTPC] Transfer finished. rx_content_len is %lu\r\n", rx_content_len);
|
||||
*req = NULL;
|
||||
xSemaphoreGive(otaSema);
|
||||
if(otaHandle != NULL){
|
||||
bl_mtd_close(otaHandle);
|
||||
if(otaBuffer != NULL) vPortFree(otaBuffer);
|
||||
utils_sha256_free(&otaCtx);
|
||||
}
|
||||
}
|
||||
|
||||
static err_t cb_httpc_headers_done_fn(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len)
|
||||
{
|
||||
unsigned int ota_addr;
|
||||
uint32_t bin_size, part_size;
|
||||
uint8_t activeID;
|
||||
|
||||
printf("[HTTPC] hdr_len is %u, content_len is %lu\r\n", hdr_len, content_len);
|
||||
int ret = bl_mtd_open(BL_MTD_PARTITION_NAME_FW_DEFAULT, &otaHandle, BL_MTD_OPEN_FLAG_BACKUP);
|
||||
if (ret) {
|
||||
printf("Open Default FW partition failed\r\n");
|
||||
return ERR_OK;
|
||||
}
|
||||
activeID = hal_boot2_get_active_partition();
|
||||
|
||||
if (hal_boot2_get_active_entries(BOOT2_PARTITION_TYPE_FW, &otaEntry)) {
|
||||
printf("PtTable_Get_Active_Entries fail\r\n");
|
||||
return ERR_OK;
|
||||
}
|
||||
ota_addr = otaEntry.Address[!otaEntry.activeIndex];
|
||||
bin_size = otaEntry.maxLen[!otaEntry.activeIndex];
|
||||
part_size = otaEntry.maxLen[!otaEntry.activeIndex];
|
||||
bl_mtd_erase_all(otaHandle);
|
||||
otaTotalLength = content_len;
|
||||
printf("otaTotalLength : %lu, bin_size : %lu\r\n", content_len, bin_size);
|
||||
if (otaTotalLength < bin_size){
|
||||
otaBuffer = pvPortMalloc(OTA_BUFFER_SIZE);
|
||||
utils_sha256_init(&otaCtx);
|
||||
utils_sha256_starts(&otaCtx);
|
||||
memset(otaSha256Result, 0, sizeof(otaSha256Result));
|
||||
}else{
|
||||
printf("otaTotalLength > bin_size abort\n");
|
||||
xSemaphoreGive(otaSema);
|
||||
if(otaHandle != NULL){
|
||||
bl_mtd_close(otaHandle);
|
||||
}
|
||||
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static err_t cb_altcp_recv_fn(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err)
|
||||
{
|
||||
printf("[HTTPC] Received %u Bytes\r\n", p->tot_len);
|
||||
|
||||
static bool otaHeader = true;
|
||||
static uint32_t flashOffset;
|
||||
static uint32_t otaOffset = 0;
|
||||
struct pbuf *lp = p;
|
||||
int use_xz;
|
||||
uint32_t ota_bin_size;
|
||||
|
||||
if(otaBuffer != NULL){
|
||||
do{
|
||||
memcpy(otaBuffer+otaOffset, lp->payload, lp->len);
|
||||
otaOffset += lp->len;
|
||||
lp = lp->next;
|
||||
} while(lp != NULL);
|
||||
printf("otaoffset : %lu\r\n", otaOffset);
|
||||
|
||||
if(otaHeader){
|
||||
if(otaOffset >= 512){
|
||||
check_ota_header((ota_header_t*)otaBuffer, &ota_bin_size, &use_xz);
|
||||
memcpy(otaSha256Img, ((ota_header_t*)otaBuffer)->u.s.sha256, sizeof(otaSha256Img));
|
||||
otaHeader = false;
|
||||
flashOffset = 0;
|
||||
for(int i=0; i<otaOffset-512; i++){
|
||||
otaBuffer[i] = otaBuffer[i+512];
|
||||
}
|
||||
otaOffset -= 512;
|
||||
}
|
||||
} else {
|
||||
utils_sha256_update(&otaCtx, otaBuffer, otaOffset);
|
||||
bl_mtd_write(otaHandle, flashOffset, otaOffset, otaBuffer);
|
||||
flashOffset += otaOffset;
|
||||
printf("Write %lu[%d]\r\n", flashOffset, otaTotalLength);
|
||||
otaOffset = 0;
|
||||
if ((flashOffset + 512) == otaTotalLength) {
|
||||
utils_sha256_finish(&otaCtx, otaSha256Result);
|
||||
printf("\r\nCalculated SHA256 Checksum:");
|
||||
for (int i = 0; i < sizeof(otaSha256Result); i++) {
|
||||
printf("%02X", otaSha256Result[i]);
|
||||
}
|
||||
printf("\r\nHeader SET SHA256 Checksum:");
|
||||
for (int i = 0; i < sizeof(otaSha256Img); i++) {
|
||||
printf("%02X", otaSha256Img[i]);
|
||||
}
|
||||
printf("\r\n");
|
||||
if (memcmp(otaSha256Img, otaSha256Result, sizeof(otaSha256Img))) {
|
||||
/*Error found*/
|
||||
printf("[OTA] [TCP] SHA256 NOT Correct\r\n");
|
||||
}
|
||||
printf("[OTA] [TCP] prepare OTA partition info\r\n");
|
||||
otaEntry.len = flashOffset;
|
||||
printf("[OTA] [TCP] Update PARTITION, partition len is %lu\r\n", otaEntry.len);
|
||||
hal_boot2_update_ptable(&otaEntry);
|
||||
hal_reboot();
|
||||
}
|
||||
}
|
||||
altcp_recved(conn,p->tot_len);
|
||||
pbuf_free(p);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
static void ota_http_cmd(char *buf, int len, int argc, char **argv)
|
||||
{
|
||||
static httpc_connection_t settings;
|
||||
static httpc_state_t *req;
|
||||
|
||||
if (2 != argc) {
|
||||
printf("Usage: %s IP\r\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("ota host=%s\n",argv[1]);
|
||||
|
||||
|
||||
otaSema = xSemaphoreCreateBinary();
|
||||
|
||||
memset(&settings, 0, sizeof(settings));
|
||||
settings.use_proxy = 0;
|
||||
settings.result_fn = cb_httpc_result;
|
||||
settings.headers_done_fn = cb_httpc_headers_done_fn;
|
||||
|
||||
httpc_get_file_dns(
|
||||
argv[1],
|
||||
8080,
|
||||
"/FW_OTA.bin.ota",
|
||||
&settings,
|
||||
cb_altcp_recv_fn,
|
||||
&req,
|
||||
&req
|
||||
);
|
||||
|
||||
xSemaphoreTake(otaSema, portMAX_DELAY);
|
||||
printf("ota download is done!\r\n");
|
||||
|
||||
vSemaphoreDelete(otaSema);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct cli_command cmds_user[] STATIC_CLI_CMD_ATTRIBUTE = {
|
||||
{"ota_http_cmd", "BL602_HTTP_OTA port ", ota_http_cmd},
|
||||
|
||||
};
|
||||
|
||||
int bl_http_ota_cli_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
13
customer_app/bl602_http_ota/bl602_http_ota/bl_http_ota.h
Normal file
13
customer_app/bl602_http_ota/bl602_http_ota/bl_http_ota.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef _BL_HTTP_OTA_H_
|
||||
#define _BL_HTTP_OTA_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int bl_http_ota_cli_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _COMMAND_H_ */
|
26
customer_app/bl602_http_ota/bl602_http_ota/bouffalo.mk
Normal file
26
customer_app/bl602_http_ota/bl602_http_ota/bouffalo.mk
Normal file
@ -0,0 +1,26 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
|
||||
include $(BL60X_SDK_PATH)/components/network/ble/ble_common.mk
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_PSM_RAM),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_PSRAM
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_CAMERA),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_CAMERA
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_BLSYNC),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_BLSYNC
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_VFS_SPI),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_VFS_SPI
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ENABLE_VFS_ROMFS),1)
|
||||
CPPFLAGS += -DCONF_USER_ENABLE_VFS_ROMFS
|
||||
endif
|
54
customer_app/bl602_http_ota/bl602_http_ota/coex_debug.c
Normal file
54
customer_app/bl602_http_ota/bl602_http_ota/coex_debug.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Bouffalolab.
|
||||
*
|
||||
* This file is part of
|
||||
* *** Bouffalolab Software Dev Kit ***
|
||||
* (see www.bouffalolab.com).
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <cli.h>
|
||||
|
||||
void coex_dump_pta(void);
|
||||
void coex_dump_wifi(void);
|
||||
|
||||
static void __attribute__((unused)) cmd_coex_dump(char *buf, int len, int argc, char **argv)
|
||||
{
|
||||
coex_dump_pta();
|
||||
coex_dump_wifi();
|
||||
}
|
||||
|
||||
const static struct cli_command cmds_user[] STATIC_CLI_CMD_ATTRIBUTE = {
|
||||
{ "coex_dump", "coex dump", cmd_coex_dump},
|
||||
};
|
||||
|
||||
int codex_debug_cli_init()
|
||||
{
|
||||
// static command(s) do NOT need to call aos_cli_register_command(s) to register.
|
||||
// However, calling aos_cli_register_command(s) here is OK but is of no effect as cmds_user are included in cmds list.
|
||||
// XXX NOTE: Calling this *empty* function is necessary to make cmds_user in this file to be kept in the final link.
|
||||
//aos_cli_register_commands(cmds_user, sizeof(cmds_user)/sizeof(cmds_user[0]));
|
||||
return 0;
|
||||
}
|
||||
|
1018
customer_app/bl602_http_ota/bl602_http_ota/main.c
Normal file
1018
customer_app/bl602_http_ota/bl602_http_ota/main.c
Normal file
File diff suppressed because it is too large
Load Diff
138
customer_app/bl602_http_ota/bl602_http_ota/wifi_prov_api.c
Normal file
138
customer_app/bl602_http_ota/bl602_http_ota/wifi_prov_api.c
Normal file
@ -0,0 +1,138 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Bouffalolab.
|
||||
*
|
||||
* This file is part of
|
||||
* *** Bouffalolab Software Dev Kit ***
|
||||
* (see www.bouffalolab.com).
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <FreeRTOS.h>
|
||||
|
||||
#include <vfs.h>
|
||||
#include <aos/kernel.h>
|
||||
#include <aos/yloop.h>
|
||||
#include <event_device.h>
|
||||
|
||||
#include "wifi_prov_api.h"
|
||||
|
||||
/*limit ssid len NOT too aggressive*/
|
||||
#define SSID_LEN_MAX (128)
|
||||
#define PASSWORD_LEN_MAX (128)
|
||||
|
||||
int wifi_prov_api_event_trigger_connect(void)
|
||||
{
|
||||
if (aos_post_event(EV_WIFI, CODE_WIFI_ON_PROV_CONNECT, 0) >= 0) {
|
||||
puts("[APP] [PROV] trigger CONNECT event OK\r\n");
|
||||
} else {
|
||||
puts("[APP] [PROV] trigger CONNECT event failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wifi_prov_api_event_trigger_disconnect(void)
|
||||
{
|
||||
if (aos_post_event(EV_WIFI, CODE_WIFI_ON_PROV_CONNECT, 0) >= 0) {
|
||||
puts("[APP] [PROV] trigger DISCONNECT event OK\r\n");
|
||||
} else {
|
||||
puts("[APP] [PROV] trigger DISCONNECT event failed\r\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wifi_prov_api_event_trigger_ssid(const char *ssid, int len)
|
||||
{
|
||||
int ret;
|
||||
int ssid_len;
|
||||
char *ssid_dup;
|
||||
|
||||
if (len) {
|
||||
ssid_len = len;
|
||||
} else {
|
||||
ssid_len = strlen(ssid);
|
||||
}
|
||||
|
||||
if (ssid_len > SSID_LEN_MAX) {
|
||||
return -1;
|
||||
}
|
||||
ssid_dup = pvPortMalloc(ssid_len + 1);
|
||||
if (NULL == ssid_dup) {
|
||||
return -1;
|
||||
}
|
||||
strncpy(ssid_dup, ssid, ssid_len);
|
||||
ssid_dup[ssid_len] = '\0';
|
||||
|
||||
puts("[APP] [PROV] sending ssid trigger ");
|
||||
puts(ssid_dup);
|
||||
puts("\r\n");
|
||||
|
||||
if ((ret = aos_post_event(EV_WIFI, CODE_WIFI_ON_PROV_SSID, (unsigned long)ssid_dup)) >= 0) {
|
||||
puts("[APP] [PROV] trigger SSID event OK\r\n");
|
||||
} else {
|
||||
printf("[APP] [PROV] trigger SSID event failed, ret %d\r\n", ret);
|
||||
vPortFree(ssid_dup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wifi_prov_api_event_trigger_password(const char *password, int len)
|
||||
{
|
||||
int password_len;
|
||||
char *password_dup;
|
||||
|
||||
if (len) {
|
||||
password_len = len;
|
||||
} else {
|
||||
password_len = strlen(password);
|
||||
}
|
||||
|
||||
if (password_len > PASSWORD_LEN_MAX) {
|
||||
return -1;
|
||||
}
|
||||
password_dup = pvPortMalloc(password_len + 1);
|
||||
if (NULL == password_dup) {
|
||||
return -1;
|
||||
}
|
||||
strncpy(password_dup, password, password_len);
|
||||
password_dup[password_len] = '\0';
|
||||
|
||||
puts("[APP] [PROV] sending password trigger ");
|
||||
puts(password_dup);
|
||||
puts("\r\n");
|
||||
|
||||
if (aos_post_event(EV_WIFI, CODE_WIFI_ON_PROV_PASSWD, (unsigned long)password_dup) >= 0) {
|
||||
puts("[APP] [PROV] trigger PASSWD event OK\r\n");
|
||||
} else {
|
||||
puts("[APP] [PROV] trigger PASSWD event failed\r\n");
|
||||
vPortFree(password_dup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
40
customer_app/bl602_http_ota/bl602_http_ota/wifi_prov_api.h
Normal file
40
customer_app/bl602_http_ota/bl602_http_ota/wifi_prov_api.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Bouffalolab.
|
||||
*
|
||||
* This file is part of
|
||||
* *** Bouffalolab Software Dev Kit ***
|
||||
* (see www.bouffalolab.com).
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of Bouffalo Lab nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#ifndef __WIFI_PROV_API_H__
|
||||
#define __WIFI_PROV_API_H__
|
||||
int wifi_prov_api_event_trigger_connect(void);
|
||||
int wifi_prov_api_event_trigger_disconnect(void);
|
||||
|
||||
/*set len to the ssid len, if ssid is NOT '\0' tailed*/
|
||||
int wifi_prov_api_event_trigger_ssid(const char *ssid, int len);
|
||||
|
||||
/*set len to the ssid len, if ssid is NOT '\0' tailed*/
|
||||
int wifi_prov_api_event_trigger_password(const char *password, int len);
|
||||
#endif
|
3
customer_app/bl602_http_ota/genromap
Normal file
3
customer_app/bl602_http_ota/genromap
Normal file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
make CONFIG_CHIP_NAME=BL602 CONFIG_LINK_ROM=1 -j
|
||||
exit $?
|
BIN
customer_app/bl602_http_ota/ota_server.jpg
Normal file
BIN
customer_app/bl602_http_ota/ota_server.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 91 KiB |
52
customer_app/bl602_http_ota/proj_config.mk
Normal file
52
customer_app/bl602_http_ota/proj_config.mk
Normal file
@ -0,0 +1,52 @@
|
||||
#
|
||||
#compiler flag config domain
|
||||
#
|
||||
#CONFIG_TOOLPREFIX :=
|
||||
#CONFIG_OPTIMIZATION_LEVEL_RELEASE := 1
|
||||
#CONFIG_M4_SOFTFP := 1
|
||||
|
||||
#
|
||||
#board config domain
|
||||
#
|
||||
CONFIG_BOARD_FLASH_SIZE := 2
|
||||
|
||||
#firmware config domain
|
||||
#
|
||||
|
||||
#set CONFIG_ENABLE_ACP to 1 to enable ACP, set to 0 or comment this line to disable
|
||||
#CONFIG_ENABLE_ACP:=1
|
||||
CONFIG_BL_IOT_FW_AP:=1
|
||||
CONFIG_BL_IOT_FW_AMPDU:=0
|
||||
CONFIG_BL_IOT_FW_AMSDU:=0
|
||||
CONFIG_BL_IOT_FW_P2P:=0
|
||||
CONFIG_ENABLE_PSM_RAM:=1
|
||||
#CONFIG_ENABLE_CAMERA:=1
|
||||
#CONFIG_ENABLE_BLSYNC:=1
|
||||
#CONFIG_ENABLE_VFS_SPI:=1
|
||||
CONFIG_ENABLE_VFS_ROMFS:=1
|
||||
|
||||
# set easyflash env psm size, only support 4K、8K、16K options
|
||||
CONFIG_ENABLE_PSM_EF_SIZE:=16K
|
||||
|
||||
CONFIG_FREERTOS_TICKLESS_MODE:=0
|
||||
|
||||
CONFIG_BT:=0
|
||||
CONFIG_BT_CENTRAL:=1
|
||||
CONFIG_BT_OBSERVER:=1
|
||||
CONFIG_BT_PERIPHERAL:=1
|
||||
CONFIG_BT_STACK_CLI:=1
|
||||
CONFIG_BT_WIFIPROV_SERVER:=1
|
||||
#CONFIG_BT_MESH := 1
|
||||
CONFIG_BLE_STACK_DBG_PRINT := 1
|
||||
CONFIG_BT_STACK_PTS := 0
|
||||
ifeq ($(CONFIG_BT_MESH),1)
|
||||
CONFIG_BT_MESH_PB_ADV := 1
|
||||
CONFIG_BT_MESH_PB_GATT := 1
|
||||
CONFIG_BT_MESH_FRIEND := 1
|
||||
CONFIG_BT_MESH_LOW_POWER := 1
|
||||
CONFIG_BT_MESH_PROXY := 1
|
||||
CONFIG_BT_MESH_GATT_PROXY := 1
|
||||
endif
|
||||
|
||||
#blog enable components format :=blog_testc cli vfs helper
|
||||
LOG_ENABLED_COMPONENTS:=blog_testc hal_drv loopset looprt bloop
|
Loading…
Reference in New Issue
Block a user