mirror of
https://github.com/Dominocs/Project_Cymple.git
synced 2025-09-26 23:49:11 +08:00
update
This commit is contained in:
parent
6b9bbdc1af
commit
3fef64e421
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmp2_eo0_t3.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmp2_eo0_t3.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmp4vr2mav5.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmp4vr2mav5.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmp_letujwd.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmp_letujwd.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpc8zpv3e2.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpc8zpv3e2.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpdts1vyo3.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpdts1vyo3.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpe3jfh_n4.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpe3jfh_n4.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpj20c6iyw.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpj20c6iyw.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpjz6pr9h3.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpjz6pr9h3.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpkyy8sjl0.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpkyy8sjl0.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpkzx9wnh5.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpkzx9wnh5.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpmyjv2lif.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpmyjv2lif.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpn0owh0bp.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpn0owh0bp.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpo4my881w.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpo4my881w.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpokr08ugh.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpokr08ugh.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpty6lg_1p.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpty6lg_1p.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpv62l90u4.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpv62l90u4.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpx0yvoob2.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpx0yvoob2.tmp
Normal file
File diff suppressed because one or more lines are too long
1
eyeTracker/software/.pio/build/esp32-cam/tmpyh2alyir.tmp
Normal file
1
eyeTracker/software/.pio/build/esp32-cam/tmpyh2alyir.tmp
Normal file
File diff suppressed because one or more lines are too long
@ -4,7 +4,7 @@
|
||||
#define CYMPLEFACE_CAM_PORT 23302
|
||||
#define CYMPLEFACE_SERVER_PORT 23303
|
||||
#define SSID_LENGTH 32
|
||||
#define WIFI_PASSWORD_LENGTH 32
|
||||
#define WIFI_PASSWORD_LENGTH 64
|
||||
#define WLAN_HEARTBEAT_TIMEOUT 5000
|
||||
#define OFFSET(structure, member) ((int32_t)&((structure*)0)->member)
|
||||
typedef struct{
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define _NETWORK_HPP
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#include "../serialMsg.h"
|
||||
namespace networkApi
|
||||
{
|
||||
static bool connect(const char *pSSID, const char *pPassword)
|
||||
@ -10,10 +10,10 @@ namespace networkApi
|
||||
WiFi.begin(pSSID, pPassword);
|
||||
if(WL_CONNECTED != WiFi.waitForConnectResult())
|
||||
{
|
||||
Serial.printf("Fail to connect to %s\n", pSSID);
|
||||
serial_writelog("Fail to connect to %s\n", pSSID);
|
||||
}
|
||||
else{
|
||||
Serial.println("Success to connect to WIFI");
|
||||
serial_writelog("Success to connect to WIFI\r\n");
|
||||
}
|
||||
return WiFi.isConnected();
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "esp32cam.h"
|
||||
#include "camCfg.h"
|
||||
#include "config.h"
|
||||
#include "serialMsg.h"
|
||||
#include "wlanMsg.h"
|
||||
#include "drv/eeprom.h"
|
||||
cameraClass *pCamera = NULL;
|
||||
@ -19,10 +20,10 @@ cameraClass::cameraClass(){
|
||||
esp_err_t err = esp_camera_init(&config);
|
||||
if (err != ESP_OK)
|
||||
{
|
||||
Serial.printf("ERROR:%d", err);
|
||||
serial_writelog("ERROR:%d\r\n", err);
|
||||
ESP_LOGE(TAG, "Camera Init Failed");
|
||||
}else{
|
||||
Serial.println("Camera succeed to init");
|
||||
serial_writelog("Camera succeed to init\r\n");
|
||||
sensor_t * s = esp_camera_sensor_get();
|
||||
s->set_brightness(s, 2); // -2 to 2
|
||||
s->set_contrast(s, 0); // -2 to 2
|
||||
@ -30,18 +31,18 @@ cameraClass::cameraClass(){
|
||||
s->set_special_effect(s, 2); // 0 to 6 (0 - No Effect, 1 - Negative, 2 - Grayscale, 3 - Red Tint, 4 - Green Tint, 5 - Blue Tint, 6 - Sepia)
|
||||
s->set_whitebal(s, 1); // 0 = disable , 1 = enable
|
||||
s->set_awb_gain(s, 1); // 0 = disable , 1 = enable
|
||||
s->set_wb_mode(s, 0); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
|
||||
s->set_wb_mode(s, 1); // 0 to 4 - if awb_gain enabled (0 - Auto, 1 - Sunny, 2 - Cloudy, 3 - Office, 4 - Home)
|
||||
s->set_exposure_ctrl(s, 1); // 0 = disable , 1 = enable
|
||||
s->set_aec2(s, 0); // 0 = disable , 1 = enable
|
||||
s->set_ae_level(s, 0); // -2 to 2
|
||||
s->set_aec_value(s, 400); // 0 to 1200
|
||||
s->set_aec_value(s, 800); // 0 to 1200
|
||||
s->set_gain_ctrl(s, 1); // 0 = disable , 1 = enable
|
||||
s->set_agc_gain(s, 0); // 0 to 30
|
||||
s->set_gainceiling(s, (gainceiling_t)0); // 0 to 6
|
||||
s->set_bpc(s, 0); // 0 = disable , 1 = enable
|
||||
s->set_wpc(s, 1); // 0 = disable , 1 = enable
|
||||
s->set_raw_gma(s, 1); // 0 = disable , 1 = enable
|
||||
s->set_lenc(s, 1); // 0 = disable , 1 = enable
|
||||
s->set_lenc(s, 0); // 0 = disable , 1 = enable
|
||||
s->set_hmirror(s, 0); // 0 = disable , 1 = enable
|
||||
s->set_vflip(s, 0); // 0 = disable , 1 = enable
|
||||
s->set_dcw(s, 1); // 0 = disable , 1 = enable
|
||||
@ -51,13 +52,13 @@ cameraClass::cameraClass(){
|
||||
}
|
||||
int cameraClass::runFrame(){
|
||||
if(!bValid){
|
||||
Serial.println("Camera failed to init");
|
||||
serial_writelog("Camera failed to init\r\n");
|
||||
return 1;
|
||||
}
|
||||
MSG_WLAN_IMAGE_S *pstImgMsg = (MSG_WLAN_IMAGE_S *)aucTxBuffer;
|
||||
camera_fb_t *pic = esp_camera_fb_get();
|
||||
if(NULL == pic){
|
||||
Serial.println("NULL == pic in cameraClass::runFrame");
|
||||
serial_writelog("NULL == pic in cameraClass::runFrame\r\n");
|
||||
return 1;
|
||||
}
|
||||
size_t imgLen = pic->len;
|
||||
@ -69,9 +70,9 @@ int cameraClass::runFrame(){
|
||||
pstImgMsg->ucFrameIndex = ucFrameIndex;
|
||||
while(imgLen > 0){
|
||||
copyLen = min(MAX_DATA_LEN, imgLen);
|
||||
pstImgMsg->tlv.uiLength = sizeof(MSG_WLAN_IMAGE_S) + copyLen;
|
||||
pstImgMsg->tlv.uiLength = sizeof(MSG_WLAN_IMAGE_S) + copyLen - sizeof(TLV_S);
|
||||
memcpy(pstImgMsg->aucData, pic->buf + pstImgMsg->uiOffset, copyLen);
|
||||
pwlanMsgObj->send(aucTxBuffer, pstImgMsg->tlv.uiLength);
|
||||
pwlanMsgObj->send(aucTxBuffer, pstImgMsg->tlv.uiLength + sizeof(TLV_S));
|
||||
pstImgMsg->uiOffset += copyLen;
|
||||
imgLen -= copyLen;
|
||||
}
|
||||
|
@ -11,9 +11,9 @@ void setup() {
|
||||
EEPROM.begin(sizeof(EEPROM_DATA_S));
|
||||
pserialObj = new serialClass();
|
||||
pwlanMsgObj = new wlanMsgClass();
|
||||
Serial.println("CympleEye WLAN Init!");
|
||||
serial_writelog("CympleEye WLAN Init!\r\n");
|
||||
pCamera = new cameraClass();
|
||||
Serial.println("CympleEye Camera Init!");
|
||||
serial_writelog("CympleEye Camera Init!\r\n");
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
@ -3,41 +3,84 @@
|
||||
#include "wlanMsg.h"
|
||||
#define SERIAL_TIMEOUT 200
|
||||
serialClass *pserialObj = NULL;
|
||||
#define LOG_BUFF_SIZE 256
|
||||
static uint8_t acSerialLogbuffer[LOG_BUFF_SIZE];
|
||||
|
||||
// 日志消息
|
||||
typedef struct {
|
||||
STREAM_TLV_S tlv;
|
||||
uint16_t logLength;
|
||||
uint8_t logLevel;
|
||||
uint8_t ucDeviceFlag;
|
||||
char data[0]; // 柔性数组成员
|
||||
} SERIAL_MSG_LOG_S;
|
||||
|
||||
|
||||
void serial_writelog(const char *format, ...) {
|
||||
SERIAL_MSG_LOG_S *pTmp = (SERIAL_MSG_LOG_S *)acSerialLogbuffer;
|
||||
pTmp->logLevel = 0;
|
||||
pTmp->ucDeviceFlag = 0;
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int16_t logSize = vsnprintf(pTmp->data, LOG_BUFF_SIZE - sizeof(SERIAL_MSG_LOG_S), format, args);
|
||||
va_end(args);
|
||||
set_stream_tlv(&pTmp->tlv, SERIAL_MSG_LOG_E, logSize + sizeof(SERIAL_MSG_LOG_S) - sizeof(STREAM_TLV_S));
|
||||
pTmp->logLength = logSize;
|
||||
Serial.write(acSerialLogbuffer, logSize + sizeof(SERIAL_MSG_LOG_S));
|
||||
}
|
||||
|
||||
serialClass::serialClass(){
|
||||
memset(acSerialRxBuffer, 0, sizeof(acSerialRxBuffer));
|
||||
Serial.begin(115200);
|
||||
Serial.println("CympleEye Serial Init!");
|
||||
}
|
||||
bool inline serialClass::getSerialMsgHead(){
|
||||
if(isValidSerialHdr(acSerialRxBuffer + usSerialRxDataOffset)){
|
||||
return true;
|
||||
serial_writelog("CympleEye Serial Init!\r\n");
|
||||
}
|
||||
|
||||
bool serialClass::getSerialMsgHead()
|
||||
{
|
||||
// 确保有足够的数据来检查消息头
|
||||
if (usSerialRxDataLen < sizeof(STREAM_TLV_S)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
STREAM_TLV_S *pTmp = (STREAM_TLV_S *)(acSerialRxBuffer + usSerialRxDataOffset);
|
||||
|
||||
// 检查前缀是否匹配
|
||||
if (pTmp->uiPrefix != STREAM_PREFIX) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查类型是否有效
|
||||
if (pTmp->uiType >= SERIAL_MSG_MAX_E) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 检查长度是否合理
|
||||
if (pTmp->uiLength > SERIAL_RX_BUFF_SIZE - sizeof(STREAM_TLV_S)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void serialClass::serialMsgCallback(uint16_t type, uint16_t len){
|
||||
switch(type){
|
||||
case SERIAL_MSG_DEVICEINFO_E:
|
||||
if(len != sizeof(SERIAL_MSG_CONNECT_S)){
|
||||
Serial.printf("Sizeof SERIAL_MSG_CONNECT_S dismatch: rcv: %u, local %u", len, sizeof(SERIAL_MSG_CONNECT_S));
|
||||
}else{
|
||||
Serial.printf("\n\nProject cympleEye\nContributor: Dominocs\nGithub & BiliBili & Vrc: Dominocs\nEmail: 1030487127@qq.com\n");
|
||||
case SERIAL_MSG_REQ_DEVICEINFO_E:
|
||||
serial_writelog("\n\nProject cympleEye\nContributor: Dominocs\nGithub & BiliBili & Vrc: Dominocs\nEmail: 1030487127@qq.com Version:DIY_1_0_0\n");
|
||||
if(WiFi.isConnected()){
|
||||
Serial.printf("Ip address:%s\n", WiFi.localIP().toString().c_str());
|
||||
}
|
||||
Serial.println();
|
||||
serial_writelog("Ip address:%s\n", WiFi.localIP().toString().c_str());
|
||||
}
|
||||
break;
|
||||
case SERIAL_MSG_WIFI_CONFIG_E:
|
||||
if(len != sizeof(SERIAL_MSG_WIFICONFIG_S)){
|
||||
Serial.printf("Sizeof SERIAL_MSG_WIFICONFIG_S dismatch: rcv: %u, local %u", len, sizeof(SERIAL_MSG_WIFICONFIG_S));
|
||||
serial_writelog("Sizeof SERIAL_MSG_WIFICONFIG_S dismatch: rcv: %u, local %u\r\n", len, sizeof(SERIAL_MSG_WIFICONFIG_S));
|
||||
}else{
|
||||
SERIAL_MSG_WIFICONFIG_S *tmp = (SERIAL_MSG_WIFICONFIG_S *)(acSerialRxBuffer + usSerialRxDataOffset);
|
||||
pwlanMsgObj->connect(tmp->acSSID, tmp->acPassword);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Serial.printf("Unrecgnized serial msg type: %u\n", type);
|
||||
serial_writelog("Unrecgnized serial msg type: %u\n", type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,8 +107,8 @@ void serialClass::runFrame(unsigned long currentT){
|
||||
}
|
||||
}
|
||||
if(bRcvSerialHdr){
|
||||
SERIAL_MSG_HDR_S *pTmp = (SERIAL_MSG_HDR_S *)(void *)(acSerialRxBuffer + usSerialRxDataOffset);
|
||||
int len = pTmp->tlv.uiLength;
|
||||
STREAM_TLV_S *pTmp = (STREAM_TLV_S *)(void *)(acSerialRxBuffer + usSerialRxDataOffset);
|
||||
int len = pTmp->uiLength + sizeof(STREAM_TLV_S);
|
||||
bRcvSerialHdr = false;
|
||||
/* 长度异常 */
|
||||
if(len > SERIAL_RX_BUFF_SIZE){
|
||||
@ -75,9 +118,11 @@ void serialClass::runFrame(unsigned long currentT){
|
||||
}
|
||||
/* 正常解析 */
|
||||
else if(usSerialRxDataLen >= len){
|
||||
serialMsgCallback(pTmp->tlv.uiType, pTmp->tlv.uiLength);
|
||||
serialMsgCallback(pTmp->uiType, pTmp->uiLength + sizeof(STREAM_TLV_S));
|
||||
usSerialRxDataLen -= len;
|
||||
usSerialRxDataOffset += len;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,21 +3,37 @@
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#define SERIAL_RX_BUFF_SIZE 1024
|
||||
enum{
|
||||
SERIAL_MSG_DEVICEINFO_E,
|
||||
// 消息类型枚举
|
||||
typedef enum {
|
||||
SERIAL_MSG_LOG_E,
|
||||
SERIAL_MSG_REQ_DEVICEINFO_E,
|
||||
SERIAL_MSG_REPLY_DEVICEINFO_E,
|
||||
SERIAL_MSG_WIFI_CONFIG_E,
|
||||
SERIAL_MSG_IMAGE_E = 5,
|
||||
SERIAL_MSG_MAX_E
|
||||
};
|
||||
} SERIAL_MSG_TYPE_E;
|
||||
|
||||
typedef struct{
|
||||
uint8_t hdr[4];
|
||||
TLV_S tlv;
|
||||
}SERIAL_MSG_HDR_S, SERIAL_MSG_CONNECT_S;
|
||||
|
||||
// TLV结构
|
||||
typedef struct {
|
||||
SERIAL_MSG_HDR_S stHdr;
|
||||
char acSSID[SSID_LENGTH];
|
||||
char acPassword[WIFI_PASSWORD_LENGTH];
|
||||
uint32_t uiPrefix;
|
||||
uint16_t uiType;
|
||||
uint16_t uiLength;
|
||||
} STREAM_TLV_S;
|
||||
|
||||
static inline void set_stream_tlv(STREAM_TLV_S *tlv, uint16_t type, uint16_t length) {
|
||||
// 设置TLV
|
||||
#define STREAM_PREFIX 0xFFDDEDFE
|
||||
tlv->uiPrefix = STREAM_PREFIX;
|
||||
tlv->uiType = type;
|
||||
tlv->uiLength = length;
|
||||
}
|
||||
|
||||
// WiFi配置消息
|
||||
typedef struct {
|
||||
STREAM_TLV_S tlv;
|
||||
char acSSID[32];
|
||||
char acPassword[64];
|
||||
} SERIAL_MSG_WIFICONFIG_S;
|
||||
|
||||
class serialClass{
|
||||
@ -37,7 +53,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
#define SERIAL_MIN_SIZE sizeof(SERIAL_MSG_HDR_S)
|
||||
|
||||
#define SERIAL_MIN_SIZE sizeof(STREAM_TLV_S)
|
||||
extern void serial_writelog(const char *format, ...);
|
||||
extern serialClass *pserialObj;
|
||||
#endif /* IMUMSG_H */
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "wlanMsg.h"
|
||||
#include "wifiUser.h"
|
||||
#include "serialMsg.h"
|
||||
|
||||
const byte DNS_PORT = 53; //设置DNS端口号
|
||||
const int webPort = 80; //设置Web端口号
|
||||
@ -35,14 +36,14 @@ void handleConfigWifi() //返回http状态
|
||||
{
|
||||
if (server.hasArg("ssid")) //判断是否有账号参数
|
||||
{
|
||||
Serial.print("got ssid:");
|
||||
serial_writelog("%s\r\n", "got ssid:");
|
||||
wifi_ssid = server.arg("ssid"); //获取html表单输入框name名为"ssid"的内容
|
||||
|
||||
Serial.println(wifi_ssid);
|
||||
serial_writelog("%s\r\n",wifi_ssid.c_str());
|
||||
}
|
||||
else //没有参数
|
||||
{
|
||||
Serial.println("error, not found ssid");
|
||||
serial_writelog("%s\r\n","error, not found ssid");
|
||||
server.send(200, "text/html", "<meta charset='UTF-8'>error, not found ssid"); //返回错误页面
|
||||
return;
|
||||
}
|
||||
@ -51,11 +52,11 @@ void handleConfigWifi() //返回http状态
|
||||
{
|
||||
Serial.print("got password:");
|
||||
wifi_pass = server.arg("password"); //获取html表单输入框name名为"pwd"的内容
|
||||
Serial.println(wifi_pass);
|
||||
serial_writelog("%s\r\n", wifi_pass.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("error, not found password");
|
||||
serial_writelog("error, not found password\r\n");
|
||||
server.send(200, "text/html", "<meta charset='UTF-8'>error, not found password");
|
||||
return;
|
||||
}
|
||||
@ -68,7 +69,7 @@ void handleConfigWifi() //返回http状态
|
||||
pwlanMsgObj->connect(wifi_ssid.c_str(), wifi_pass.c_str());
|
||||
}
|
||||
else {
|
||||
Serial.println("提交的配置信息自动连接成功..");
|
||||
serial_writelog("提交的配置信息自动连接成功..\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,9 +89,9 @@ void initDNS()
|
||||
{
|
||||
if (dnsServer.start(DNS_PORT, "*", apIP)) //判断将所有地址映射到esp32的ip上是否成功
|
||||
{
|
||||
Serial.println("start dnsserver success.");
|
||||
serial_writelog("start dnsserver success.\r\n");
|
||||
} else {
|
||||
Serial.println("start dnsserver failed.");
|
||||
serial_writelog("start dnsserver failed.\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +102,7 @@ void initWebServer()
|
||||
{
|
||||
if (MDNS.begin("esp32")) //给设备设定域名esp32,完整的域名是esp32.local
|
||||
{
|
||||
Serial.println("MDNS responder started");
|
||||
serial_writelog("MDNS responder started\r\n");
|
||||
}
|
||||
//必须添加第二个参数HTTP_GET,以下面这种格式去写,否则无法强制门户
|
||||
server.on("/", HTTP_GET, handleRoot); // 当浏览器请求服务器根目录(网站首页)时调用自定义函数handleRoot处理,设置主页回调函数,必须添加第二个参数HTTP_GET,否则无法强制门户
|
||||
@ -111,25 +112,25 @@ void initWebServer()
|
||||
|
||||
server.begin(); //启动TCP SERVER
|
||||
|
||||
Serial.println("WebServer started!");
|
||||
serial_writelog("WebServer started!\r\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* 扫描附近的WiFi,为了显示在配网界面
|
||||
*/
|
||||
bool scanWiFi() {
|
||||
Serial.println("scan start");
|
||||
Serial.println("--------->");
|
||||
serial_writelog("scan start\r\n");
|
||||
serial_writelog("--------->\r\n");
|
||||
// 扫描附近WiFi
|
||||
int n = WiFi.scanNetworks();
|
||||
Serial.println("scan done");
|
||||
serial_writelog("scan done\r\n");
|
||||
if (n == 0) {
|
||||
Serial.println("no networks found");
|
||||
serial_writelog("no networks found\r\n");
|
||||
scanNetworksID += "<option>no networks found</option>";
|
||||
return false;
|
||||
} else {
|
||||
Serial.print(n);
|
||||
Serial.println(" networks found");
|
||||
serial_writelog(" networks found\r\n");
|
||||
for (int i = 0; i < n; ++i) {
|
||||
// Print SSID and RSSI for each network found
|
||||
Serial.print(i + 1);
|
||||
@ -138,7 +139,7 @@ bool scanWiFi() {
|
||||
Serial.print(" (");
|
||||
Serial.print(WiFi.RSSI(i));
|
||||
Serial.print(")");
|
||||
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
|
||||
serial_writelog((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
|
||||
scanNetworksID += "<option>" + WiFi.SSID(i) + "</option>";
|
||||
delay(10);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "wlanMsg.h"
|
||||
#include <esp_wifi.h>
|
||||
#include "wifiUser.h"
|
||||
#include "serialMsg.h"
|
||||
|
||||
#define WIFI_MAX_TX_POWER 80
|
||||
wlanMsgClass *pwlanMsgObj = NULL;
|
||||
@ -37,7 +38,7 @@ static void onPacketCallBack(AsyncUDPPacket packet){
|
||||
eepromApi::write(&pstMsg->ucPosition, OFFSET(EEPROM_DATA_S, ucFlags), sizeof(pstMsg->ucPosition));
|
||||
pCamera->ucFlags = pstMsg->ucPosition;
|
||||
}else{
|
||||
Serial.printf("Mismatch: sizeof(MSG_WLAN_PARACONFIG_S):%u, msg len:%d\n", sizeof(MSG_WLAN_POSIOTN_CONFIG_S), msgLen);
|
||||
serial_writelog("Mismatch: sizeof(MSG_WLAN_PARACONFIG_S):%u, msg len:%d\n", sizeof(MSG_WLAN_POSIOTN_CONFIG_S), msgLen);
|
||||
}
|
||||
break;
|
||||
// case MSG_REFRESH_RATE_CFT_E:
|
||||
@ -50,12 +51,12 @@ static void onPacketCallBack(AsyncUDPPacket packet){
|
||||
// }
|
||||
// ucFlag2 = flag;
|
||||
// eepromApi::write(&flag, OFFSET(EEPROM_DATA_S, ucFlags2), sizeof(flag));
|
||||
// Serial.printf("Switch fresh rate: flag2:%d\n", ucFlag2);
|
||||
// serial_writelog("Switch fresh rate: flag2:%d\n", ucFlag2);
|
||||
// break;
|
||||
}
|
||||
case MSG_CONFIG_WIFI_E:{
|
||||
if(msgLen != sizeof(MSG_WLAN_WIFI_CONFIG_S)){
|
||||
Serial.printf("Sizeof MSG_WLAN_WIFI_CONFIG_S dismatch: rcv: %u, local %u", msgLen, sizeof(MSG_WLAN_WIFI_CONFIG_S));
|
||||
serial_writelog("Sizeof MSG_WLAN_WIFI_CONFIG_S dismatch: rcv: %u, local %u\r\n", msgLen, sizeof(MSG_WLAN_WIFI_CONFIG_S));
|
||||
}else{
|
||||
MSG_WLAN_WIFI_CONFIG_S *tmp = (MSG_WLAN_WIFI_CONFIG_S *)pstMsgHdr;
|
||||
tmp->SSID[SSID_LENGTH - 1] = '\0';
|
||||
@ -68,7 +69,7 @@ static void onPacketCallBack(AsyncUDPPacket packet){
|
||||
}
|
||||
|
||||
default:
|
||||
Serial.printf("Invalid msg type%u, msg len:%d\n", pstMsgHdr->uiType, msgLen);
|
||||
serial_writelog("Invalid msg type%u, msg len:%d\n", pstMsgHdr->uiType, msgLen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -84,7 +85,7 @@ wlanMsgClass::wlanMsgClass(){
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.persistent(false);
|
||||
// if(ESP_OK != esp_wifi_set_max_tx_power(WIFI_MAX_TX_POWER)){
|
||||
// Serial.println("Failed to config wifi max tx power.");
|
||||
// serial_writelog("Failed to config wifi max tx power.");
|
||||
// }
|
||||
while (!udpClient.listen(CYMPLEFACE_CAM_PORT)) //等待udp监听设置成功
|
||||
{
|
||||
@ -94,10 +95,11 @@ wlanMsgClass::wlanMsgClass(){
|
||||
connect(acSSID, acPassword);
|
||||
}
|
||||
}
|
||||
|
||||
void wlanMsgClass::connect(const char *SSID, const char *password){
|
||||
bool ret = false;
|
||||
if(0 == SSID[0]){
|
||||
Serial.println("SSID missing");
|
||||
serial_writelog("SSID missing\r\n");
|
||||
}
|
||||
if(0 != strcmp(SSID, acSSID)){
|
||||
ret = true;
|
||||
@ -110,14 +112,14 @@ void wlanMsgClass::connect(const char *SSID, const char *password){
|
||||
eepromApi::write((void *)password, OFFSET(EEPROM_DATA_S, acPassword), WIFI_PASSWORD_LENGTH);
|
||||
}
|
||||
if(ret){
|
||||
Serial.printf("Connecting to %s\n", acSSID);
|
||||
serial_writelog("Connecting to %s\n", acSSID);
|
||||
networkApi::connect(acSSID, acPassword);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wlanMsgClass::connect(){
|
||||
Serial.printf("Connecting to %s\n", acSSID);
|
||||
serial_writelog("Connecting to %s\n", acSSID);
|
||||
networkApi::connect(acSSID, acPassword);
|
||||
}
|
||||
|
||||
@ -131,7 +133,7 @@ void wlanMsgClass::APMode(){
|
||||
|
||||
void wlanMsgClass::send(uint8_t *data, size_t len, IPAddress ip, uint16_t port){
|
||||
if(len > CONFIG_TCP_MSS){
|
||||
Serial.printf("wlanMsgClass::send: data too large:%u\n", len);
|
||||
serial_writelog("wlanMsgClass::send: data too large:%u\n", len);
|
||||
return;
|
||||
}
|
||||
udpClient.writeTo(data, len, ip, port);
|
||||
@ -149,7 +151,7 @@ void wlanMsgClass::send(uint8_t *data, size_t len){
|
||||
int wlanMsgClass::runFrame(unsigned long currentT){
|
||||
if(tryConCount > 2){
|
||||
if(3 == tryConCount){
|
||||
Serial.println("Wating to config WIFI");
|
||||
serial_writelog("Wating to config WIFI\r\n");
|
||||
APMode();
|
||||
tryConCount++;
|
||||
}
|
||||
@ -164,13 +166,13 @@ int wlanMsgClass::runFrame(unsigned long currentT){
|
||||
}
|
||||
if(bHeartbeatTimeout){
|
||||
if(!WiFi.isConnected()){
|
||||
Serial.println("Wlan disconnected");
|
||||
serial_writelog("Wlan disconnected\r\n");
|
||||
tryConCount++;
|
||||
connect();
|
||||
delay(3000);
|
||||
return 1;
|
||||
}else{
|
||||
Serial.println("Heartbeat timeout");
|
||||
serial_writelog("Heartbeat timeout\r\n");
|
||||
delay(1000);
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user