Browse Source

updated tests, changed file names, new mesh packet type

feature/mesh_network
Hendrik Schutter 1 year ago
parent
commit
c17756160f
  1. 2
      components/mesh_ota/CMakeLists.txt
  2. 2
      components/mesh_ota/Mesh_OTA.c
  3. 50
      components/mesh_ota/Mesh_network.c
  4. 7
      components/mesh_ota/Mesh_network_handler.c
  5. 15
      components/mesh_ota/include/Mesh_OTA.h
  6. 78
      components/mesh_ota/include/Mesh_network.h
  7. 35
      components/mesh_ota/include/mesh_network.h
  8. 2
      components/mesh_ota/test/test_mesh_ota.c
  9. 2
      main/CMakeLists.txt
  10. 13
      main/Kconfig.projbuild
  11. 9
      main/Main.c
  12. 2
      sdkconfig

2
components/mesh_ota/CMakeLists.txt

@ -1,4 +1,4 @@
idf_component_register(SRCS "mesh_network_handler.c" "mesh_network.c" "mesh_ota.c"
idf_component_register(SRCS "Mesh_network_handler.c" "Mesh_network.c" "Mesh_OTA.c"
INCLUDE_DIRS "include"
REQUIRES nvs_flash
esp_http_client

2
components/mesh_ota/mesh_ota.c → components/mesh_ota/Mesh_OTA.c

@ -1,4 +1,4 @@
#include "mesh_ota.h"
#include "Mesh_OTA.h"
/*
* 999.999.999

50
components/mesh_ota/mesh_network.c → components/mesh_ota/Mesh_network.c

@ -1,11 +1,14 @@
#include "mesh_ota.h"
#include "Mesh_OTA.h"
static const char *LOG_TAG = "mesh_network";
static const uint8_t MESH_ID[6] = { 0x77, 0x77, 0x77, 0x77, 0x77, 0x77};
static uint8_t tx_buf[TX_SIZE] = { 0, };
static uint8_t rx_buf[RX_SIZE] = { 0, };
static uint8_t tx_buf[CONFIG_MESH_MESSAGE_SIZE] = { 0, };
static uint8_t rx_buf[CONFIG_MESH_MESSAGE_SIZE] = { 0, };
static uint8_t u8NodeMAC[6];
esp_netif_t* netif_sta;
bool bIsMeshConnected;
int32_t i32MeshLayer;
mesh_addr_t mesh_parent_addr;
esp_err_t errMeshNetworkInitialize()
{
@ -13,7 +16,7 @@ esp_err_t errMeshNetworkInitialize()
esp_err_t err;
bIsMeshConnected = false;
i32MeshLayer = -1;
//netif_sta = NULL;
netif_sta = NULL;
err = nvs_flash_init(); //init non-volatile storage
@ -57,7 +60,7 @@ esp_err_t errMeshNetworkInitialize()
mesh_cfg_t cfg = MESH_INIT_CONFIG_DEFAULT();
/* mesh ID */
memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6);
memcpy((uint8_t *) &cfg.mesh_id, CONFIG_MESH_ID, 6);
ERROR_CHECK(errMeshNetworkInitializeRouter(&cfg));
@ -150,8 +153,7 @@ esp_err_t errGetChildren(mesh_addr_t* pChildren, uint16_t* pu16ChildrenSize)
return err;
}
/*
esp_err_t errSendPacket(mesh_addr_t* dest, struct ota_mesh_packet* packet)
esp_err_t errSendMeshPacket(mesh_addr_t* pAddrDest, MESH_PACKET_t* pPacket)
{
esp_err_t err;
mesh_data_t data;
@ -159,28 +161,23 @@ esp_err_t errSendPacket(mesh_addr_t* dest, struct ota_mesh_packet* packet)
data.size = sizeof(tx_buf);
data.proto = MESH_PROTO_BIN;
data.tos = MESH_TOS_P2P;
memcpy(tx_buf, (uint8_t *)packet, sizeof(struct ota_mesh_packet));
err = esp_mesh_send(dest, &data, MESH_DATA_P2P, NULL, 0);
memcpy(tx_buf, (uint8_t *)pPacket, sizeof(MESH_PACKET_t));
err = esp_mesh_send(pAddrDest, &data, MESH_DATA_P2P, NULL, 0);
return err;
}
*/
esp_err_t errStartReceiveTask()
{
esp_err_t err = ESP_OK;
BaseType_t xReturned;
//static bool is_comm_p2p_started = false;
// if (!is_comm_p2p_started)
// {
//is_comm_p2p_started = true;
xReturned = xTaskCreate(vTaskReceiveMeshData, "ReceiveMeshData", 7000, NULL, 5, NULL);
if(xReturned != pdPASS)
{
err = ESP_FAIL;
}
//}
xReturned = xTaskCreate(vTaskReceiveMeshData, "ReceiveMeshData", 7000, NULL, 5, NULL);
if(xReturned != pdPASS)
{
err = ESP_FAIL;
}
return err;
}
@ -191,11 +188,11 @@ void vTaskReceiveMeshData(void *arg)
mesh_data_t data;
int flag = 0;
data.data = rx_buf;
data.size = RX_SIZE;
data.size = CONFIG_MESH_MESSAGE_SIZE;
while (true)
{
data.size = RX_SIZE;
data.size = CONFIG_MESH_MESSAGE_SIZE;
err = esp_mesh_recv(&from, &data, portMAX_DELAY, &flag, NULL, 0);
if (err != ESP_OK || !data.size)
{
@ -204,7 +201,7 @@ void vTaskReceiveMeshData(void *arg)
}
/*
struct ota_mesh_packet packet;
memcpy(&packet, (uint8_t *)rx_buf, sizeof(struct ota_mesh_packet));
@ -239,8 +236,9 @@ void vTaskReceiveMeshData(void *arg)
break;
}//end switch
*/
} //end while
vTaskDelete(NULL);
}

7
components/mesh_ota/mesh_network_handler.c → components/mesh_ota/Mesh_network_handler.c

@ -1,5 +1,5 @@
#include "mesh_ota.h"
#include "Mesh_OTA.h"
static const char *LOG_TAG = "mesh_network_handler";
@ -85,10 +85,7 @@ void vMeshEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventI
bIsMeshConnected = true;
if (esp_mesh_is_root())
{
ESP_LOGE(LOG_TAG, "addr %p", netif_sta);
//ESP_ERROR_CHECK(esp_netif_dhcpc_start(netif_sta)); //get a IP from router
ESP_ERROR_CHECK(esp_netif_dhcpc_start(netif_sta)); //get a IP from router
}
errStartReceiveTask();//start receiving
}

15
components/mesh_ota/include/mesh_ota.h → components/mesh_ota/include/Mesh_OTA.h

@ -13,23 +13,20 @@
#include "esp_ota_ops.h"
#include "esp_partition.h"
#include "mesh_network.h"
#include "Mesh_network.h"
#define ERASE_NVS //erase non volatile storage if full
struct ota_mesh_packet
{
enum ota_mesh_packet_type
/*
enum ota_packet_type
{
APP_Version_Request,
APP_Version_Response,
OTA_Data,
OTA_ACK,
OTA_Complete
} type;
uint8_t au8Payload[1024];
};
};
*/
#define ERROR_CHECK(x) if (err == ESP_OK) \
{ \
@ -45,6 +42,4 @@ bool bNewerVersion(const char* pu8Local, const char* pu8Remote);
esp_err_t errExtractVersionNumber(const char* pu8Data, uint32_t* pu32DataLenght, char* pc8RemoteVersionNumber);
esp_err_t errFindImageStart(const char* pu8Data, uint32_t* pu32DataLenght, uint32_t* pu32StartOffset);
#endif /* H_MESH_OTA */

78
components/mesh_ota/include/Mesh_network.h

@ -0,0 +1,78 @@
#ifndef H_MESH_NETWORK
#define H_MESH_NETWORK
#include <string.h>
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_mesh.h"
#include "esp_mesh_internal.h"
#ifndef CONFIG_MESH_MESSAGE_SIZE
#define CONFIG_MESH_MESSAGE_SIZE 1500
#endif
#ifndef CONFIG_MESH_TOPOLOGY
#define CONFIG_MESH_TOPOLOGY MESH_TOPO_TREE
#endif
#ifndef CONFIG_MESH_MAX_LAYER
#define CONFIG_MESH_MAX_LAYER 6
#endif
#ifndef CONFIG_MESH_ID
#define CONFIG_MESH_ID "00, 00, 00, 00, 00, 00"
#endif
#ifndef CONFIG_MESH_AP_AUTHMODE
#define CONFIG_MESH_AP_AUTHMODE WIFI_AUTH_WPA2_PSK
#endif
#ifndef CONFIG_MESH_AP_CONNECTIONS
#define CONFIG_MESH_AP_CONNECTIONS 6
#endif
#ifndef CONFIG_MESH_AP_PASSWD
#define CONFIG_MESH_AP_PASSWD "MAP_PASSWD"
#endif
#ifndef CONFIG_MESH_CHANNEL
#define CONFIG_MESH_CHANNEL 0
#endif
#ifndef CONFIG_MESH_ROUTER_SSID
#define CONFIG_MESH_ROUTER_SSID "ROUTER_SSID"
#endif
#ifndef CONFIG_MESH_ROUTER_PASSWD
#define CONFIG_MESH_ROUTER_PASSWD "ROUTER_PASSWD"
#endif
#ifndef CONFIG_MESH_ROUTE_TABLE_SIZE
#define CONFIG_MESH_ROUTE_TABLE_SIZE 50
#endif
struct mesh_packet
{
//todo type
//todo lenght
uint8_t au8Payload[1024];
};
typedef struct mesh_packet MESH_PACKET_t;
extern bool bIsMeshConnected;
extern int32_t i32MeshLayer;
extern mesh_addr_t mesh_parent_addr;
extern esp_netif_t* netif_sta;
esp_err_t errMeshNetworkInitialize();
esp_err_t errMeshNetworkInitializeWiFi();
esp_err_t errMeshNetworkInitializeRouter(mesh_cfg_t* cfg);
bool bCheckMACEquality(uint8_t* pu8aMAC, uint8_t* pu8bMAC);
esp_err_t errGetChildren(mesh_addr_t* pChildren, uint16_t* pu16ChildrenSize);
void vMeshEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventID, void* vpEventData);
void vIPEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventID, void *event_data);
esp_err_t errStartReceiveTask();
void vTaskReceiveMeshData(void *arg);
esp_err_t errSendMeshPacket(mesh_addr_t* pAddrDest, MESH_PACKET_t* pPacket);
#endif /* H_MESH_NETWORK */

35
components/mesh_ota/include/mesh_network.h

@ -1,35 +0,0 @@
#ifndef H_MESH_NETWORK
#define H_MESH_NETWORK
#include <string.h>
#include "esp_wifi.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_mesh.h"
#include "esp_mesh_internal.h"
#define RX_SIZE (1234)
#define TX_SIZE (1234)
static bool bIsMeshConnected;
static int32_t i32MeshLayer;
static mesh_addr_t mesh_parent_addr;
static esp_netif_t *netif_sta = NULL;
esp_err_t errMeshNetworkInitialize();
esp_err_t errMeshNetworkInitializeWiFi();
esp_err_t errMeshNetworkInitializeRouter(mesh_cfg_t* cfg);
bool bCheckMACEquality(uint8_t* pu8aMAC, uint8_t* pu8bMAC);
esp_err_t errGetChildren(mesh_addr_t* pChildren, uint16_t* pu16ChildrenSize);
esp_err_t errSendPacket(mesh_addr_t* dest, struct ota_mesh_packet* packet);
void vMeshEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventID, void* vpEventData);
void vIPEventHandler(void *arg, esp_event_base_t event_base, int32_t i32EventID, void *event_data);
esp_err_t errStartReceiveTask();
void vTaskReceiveMeshData(void *arg);
#endif /* H_MESH_NETWORK */

2
components/mesh_ota/test/test_mesh_ota.c

@ -1,7 +1,7 @@
#include <limits.h>
#include "unity.h"
#include "mesh_ota.h"
#include "Mesh_OTA.h"
#include "test_image_hex.h"
// ### ### ### distinguish newer image version ### ### ###

2
main/CMakeLists.txt

@ -1,2 +1,2 @@
idf_component_register(SRCS "main.c"
idf_component_register(SRCS "Main.c"
INCLUDE_DIRS ".")

13
main/Kconfig.projbuild

@ -105,6 +105,12 @@ menu "Mesh OTA Configuration"
default 0
help
mesh network channel.
config MESH_ID
string "ID for mesh network"
default "00, 00, 00, 00, 00, 00"
help
Mesh network id like MAC addr.
config MESH_ROUTER_SSID
string "Router SSID"
@ -158,6 +164,13 @@ menu "Mesh OTA Configuration"
help
The number of devices over the network(max: 300).
config MESH_MESSAGE_SIZE
int "Mesh network messages size"
range 1 65536
default 1500
help
Length of messages deliveres by the mesh network.
config OTA_HTTPS_SERVER_COMMON_NAME
string "Common name OTA server"
default "exmaple.com"

9
main/main.c → main/Main.c

@ -11,13 +11,10 @@
#include "esp_ota_ops.h"
#include "esp_partition.h"
#include "mesh_ota.h"
#include "Mesh_OTA.h"
static const char *LOG_TAG = "esp_main";
void app_main(void)
{
esp_err_t err = ESP_OK;
@ -29,10 +26,6 @@ void app_main(void)
//start app
}

2
sdkconfig

@ -150,6 +150,7 @@ CONFIG_MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE=y
CONFIG_MESH_PS_NWK_DUTY_RULE=0
CONFIG_MESH_MAX_LAYER=6
CONFIG_MESH_CHANNEL=13
CONFIG_MESH_ID="00, 00, 00, 00, 00, 00"
CONFIG_MESH_ROUTER_SSID="labNet"
CONFIG_MESH_ROUTER_PASSWD="12345678"
CONFIG_WIFI_AUTH_WPA2_PSK=y
@ -158,6 +159,7 @@ CONFIG_MESH_AP_AUTHMODE=3
CONFIG_MESH_AP_PASSWD="qaws1234"
CONFIG_MESH_AP_CONNECTIONS=6
CONFIG_MESH_ROUTE_TABLE_SIZE=50
CONFIG_MESH_MESSAGE_SIZE=1500
CONFIG_OTA_HTTPS_SERVER_COMMON_NAME="ota.hendrikschutter.com"
CONFIG_OTA_HTTPS_SERVER_PORT="443"
CONFIG_OTA_HTTPS_URL="https://ota.hendrikschutter.com/mesh_ota.bin"

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close