当前位置: 首页 > news >正文

ESP8266 WiFi物联网智能插座—下位机软件实现

目录

1、软件架构

2、开发环境 

3、软件功能

4、程序设计

4.1、初始化

4.2、主循环状态机

4.3、初始化模式

4.4、配置模式

4.5、运行模式

4.6、重启模式

4.7、升级模式

5、程序功能特点

5.1、日志管理

5.2、数据缓存队列


本篇博文开始讲解下位机插座节点的MCU软件程序是如何实现。

1、软件架构

下位机软件架构采用前后台控制系统,使用状态机思维实现程序设计。

2、开发环境 

开发环境使用Arduino IDE,IDE安装过程可参见:https://handsome-man.blog.csdn.net/article/details/121195905

智能插座的控制器是ESP8266,需要在IDE中安装该开发包,如下图所示:

3、软件功能

下位机软件整功能如下图所示:

4、程序设计

4.1、初始化

节点上电后会执行初始化,初始化程序顺序执行,代码如下所示:

  Init_Log();Log.verboseln("config start!");Log.verboseln("init IO");Init_IO();Log.verboseln("IO OK!");Log.verboseln("init EEPROM");Init_EEPROM();if(Device_VariableInitial(MODE1) == STATUS_SUCCESS){Log.verboseln("EEPROM OK!");}else{Log.errorln("EEPROM ERROR!");}Log.verboseln("init data queue");Init_queue();Log.verboseln("data queue OK!");Log.verboseln("init WiFi and server");if(Init_WIFI() == STATUS_SUCCESS){Log.verboseln("WiFi and server OK!");}else{Log.errorln("WiFi and server ERROR!");}Log.verboseln("init time");Init_Time();Log.verboseln("time OK!");Log.verboseln("init electrical parameter");// Init_BL0942();  // 串口初始化时,已经初始化波特率Log.verboseln("electrical parameter OK!");Log.verboseln("config end!");program_state.run_state = INIT_STATE;

初始化时候有两点需要注意:

1、节点的日志打印和采集电参数据使用同一路UART,在正式版本软件中,为了避免出现数据错乱的问题,需要将日志打印功能关闭,使#define LOG_OFF 0

 /********************************************************************************** \brief  初始化log日志模块**** \param  无**** \retval 无********************************************************************************/
void Init_Log(void)
{Serial.begin(4800, SERIAL_8N1);  // 4800bps 无校验Serial.println();Log.setPrefix(printPrefix); // set prefix similar to NLogLog.setSuffix(printSuffix); // set suffix Log.begin(LOG_LEVEL_VERBOSE, &Serial);Log.setShowLevel(false);    // Do not show loglevel, we will do this in the prefix#if LOG_OFFDeInit_Log();#endif
}

 2、E2PROM使用ESP8266内置的Flash模拟。默认情况下,每次线烧程序、OTA升级程序,这部分存储的配置并不会覆盖或者更新,只有上位机下发更新配置参数才会修改。如果想线烧程序更改配置,需要先将标志位#define DEVICE_FLAG   0XAA55修改成非0XAA55的其他数值。

4.2、主循环状态机

在主循环中使用1ms周期调度维护软件状态机,节点运行有5种状态模式:初始化模式、配置模式、运行模式、重启模式和升级模式。节点默认处于运行模式,代码如下所示:

    switch(program_state.run_state){// 初始化模式case INIT_STATE:Init_State();break;// 配置模式case CONFIG_STATE:Config_State();break;// 运行模式case RUN_STATE:Run_State();break;// 重启模式case RESET_STATE:Reset_State();break;// 升级模式case UPDATA_STATE:Updata_State();break;}

4.3、初始化模式

初始化模式中初始化一些变量数据。

初始化模式中,有一个机制,第一次连接立刻上传一次数据到服务器,否则就按照默认的60秒周期上报数据,第一次上报数据会很慢。代码如下所示:

 /********************************************************************************** \brief  初始化状态逻辑**** \param  无**** \retval 无********************************************************************************/
void Init_State(void)
{wifi_send_data.device_head = DeviceParamSave.device_head + FUNCTION_ID1;wifi_send_data.device_id = DeviceParamSave.device_id;memcpy(&(wifi_send_data.software_version), &(DeviceParamSave.software_version), 15);memcpy(&(wifi_send_data.hardware_version), &(DeviceParamSave.hardware_version), 15);memcpy(&(wifi_send_data.release_time), &(DeviceParamSave.release_time), 10);wifi_send_data.upload_cycle = DeviceParamSave.upload_cycle;wifi_send_data.sample_cycle = DeviceParamSave.sample_cycle;program_state.run_state_time = (DeviceParamSave.upload_cycle * 1000);  // 第一次连接立刻上传一次数据到服务器program_state.run_state = RUN_STATE;
}

4.4、配置模式

配置模式可接收上位机下发的配置参数,存储到节点E2PROM中。

配置模式有超时机制,3分钟上位机未下发配置参数,自动跳转到运行模式。

更新配置参数后,由配置模式切换到重启模式,节电重启。

代码如下所示:

 /********************************************************************************** \brief  配置状态逻辑**** \param  无**** \retval 无********************************************************************************/
void Config_State(void)
{program_state.config_state_time++;if(program_state.config_state_time >= CYCLE_TIME_180SEC){LED_OFF;program_state.config_state_time = 0;program_state.run_state = RUN_STATE;Log.warningln("config timeout");Log.warningln("switch run state");}// 处理WiFi接收的数据if(wifi_receive_flag == true){if(receive_data[0] == DeviceParamSave.device_head + FUNCTION_ID4){memcpy(&wifi_receive_config, receive_data, sizeof(ReceiveConfig_t));if((wifi_receive_config.device_old_head == (DeviceParamSave.device_head + FUNCTION_ID4)) && (wifi_receive_config.device_old_id == (DeviceParamSave.device_id) || (wifi_receive_config.device_old_id == 0XFFFF))){crc_temp = check_crc16((uint8_t *)&wifi_receive_config, wifi_receive_config.device_len - 2);if(wifi_receive_config.crc == crc_temp){if(wifi_receive_config.device_config_type == 0) // 默认配置{Log.verboseln("default setting...");DeviceParamSave.device_flag = DEVICE_FLAG;if((wifi_receive_config.device_new_head != 0) && (wifi_receive_config.device_new_head !=  DeviceParamSave.device_head)){DeviceParamSave.device_head = wifi_receive_config.device_new_head;}else{Log.verboseln("DEVICE_HEAD 0 or invariant");}if((wifi_receive_config.device_new_id != 0) && (wifi_receive_config.device_new_id !=  DeviceParamSave.device_id)){DeviceParamSave.device_id = wifi_receive_config.device_new_id;}else{Log.verboseln("DEVICE_ID 0 or invariant");}if((strcmp(wifi_receive_config.software_version, "") != 0) && (strcmp(wifi_receive_config.software_version, DeviceParamSave.software_version) != 0)){memcpy(&(DeviceParamSave.software_version), &(wifi_receive_config.software_version), 15);}else{Log.verboseln("SW_VERSION null or invariant");}if((strcmp(wifi_receive_config.hardware_version, "") != 0) && (strcmp(wifi_receive_config.hardware_version, DeviceParamSave.hardware_version) != 0)){memcpy(&(DeviceParamSave.hardware_version), &(wifi_receive_config.hardware_version), 15);}else{Log.verboseln("HW_VERSION null or invariant");}if((strcmp(wifi_receive_config.release_time, "") != 0) && (strcmp(wifi_receive_config.release_time, DeviceParamSave.release_time) != 0)){memcpy(&(DeviceParamSave.release_time), &(wifi_receive_config.release_time), 10);}else{Log.verboseln("RELEASE_TIME null or invariant");}if((wifi_receive_config.upload_cycle != 0) && (wifi_receive_config.upload_cycle !=  DeviceParamSave.upload_cycle)){DeviceParamSave.upload_cycle = wifi_receive_config.upload_cycle;}else{Log.verboseln("UPLOAD_CYCLE 0 or invariant");}if((wifi_receive_config.sample_cycle != 0) && (wifi_receive_config.sample_cycle !=  DeviceParamSave.sample_cycle)){DeviceParamSave.sample_cycle = wifi_receive_config.sample_cycle;}else{Log.verboseln("SAMPLE_CYCLE 0 or invariant");}if((strcmp(wifi_receive_config.wifi_ssid, "") != 0) && (strcmp(wifi_receive_config.wifi_ssid, DeviceParamSave.wifi_ssid) != 0)){memcpy(&(DeviceParamSave.wifi_ssid), &(wifi_receive_config.wifi_ssid), 64);}else{Log.verboseln("WIFI_SSID null or invariant");}if((strcmp(wifi_receive_config.wifi_password, "") != 0) && (strcmp(wifi_receive_config.wifi_password, DeviceParamSave.wifi_password) != 0)){memcpy(&(DeviceParamSave.wifi_password), &(wifi_receive_config.wifi_password), 64);}else{Log.verboseln("WIFI_PASSWORD null or invariant");}if((strcmp(wifi_receive_config.server_ip, "") != 0) && (strcmp(wifi_receive_config.server_ip, DeviceParamSave.server_ip) != 0)){memcpy(&(DeviceParamSave.server_ip), &(wifi_receive_config.server_ip), 64);}else{Log.verboseln("SERVER_IP null or invariant");}if((wifi_receive_config.server_port != 0) && (wifi_receive_config.server_port !=  DeviceParamSave.server_port)){DeviceParamSave.server_port = wifi_receive_config.server_port;}else{Log.verboseln("SERVER_PORT 0 or invariant");}}else if(wifi_receive_config.device_config_type == 1) // 恢复出厂设置{Log.verboseln("factory data reset...");DeviceParamSave.device_flag = DEVICE_FLAG;DeviceParamSave.device_head = DEVICE_HEAD;DeviceParamSave.device_id = DEVICE_ID;memcpy(&(DeviceParamSave.software_version), SW_VERSION, strlen(SW_VERSION));memcpy(&(DeviceParamSave.hardware_version), HW_VERSION, strlen(HW_VERSION));memcpy(&(DeviceParamSave.release_time), RELEASE_TIME, strlen(RELEASE_TIME));DeviceParamSave.upload_cycle = UPLOAD_CYCLE;DeviceParamSave.sample_cycle = SAMPLE_CYCLE;memcpy(&(DeviceParamSave.wifi_ssid), WIFI_SSID, strlen(WIFI_SSID));memcpy(&(DeviceParamSave.wifi_password), WIFI_PASSWORD, strlen(WIFI_PASSWORD));memcpy(&(DeviceParamSave.server_ip), SERVER_IP, strlen(SERVER_IP));DeviceParamSave.server_port = SERVER_PORT;}DeviceParamSave.crc = check_crc16((uint8_t *)&DeviceParamSave, sizeof(DeviceParamSave_t) - 2);Log.verboseln("DEVICE_HEAD:0X%X", DeviceParamSave.device_head);Log.verboseln("DEVICE_ID:0X%X", DeviceParamSave.device_id);Log.verboseln("SW_VERSION:%S", DeviceParamSave.software_version);Log.verboseln("HW_VERSION:%S", DeviceParamSave.hardware_version);Log.verboseln("RELEASE_TIME:%S", DeviceParamSave.release_time);Log.verboseln("UPLOAD_CYCLE:%d", DeviceParamSave.upload_cycle);Log.verboseln("SAMPLE_CYCLE:%d", DeviceParamSave.sample_cycle);Log.verboseln("WIFI_SSID:%S", DeviceParamSave.wifi_ssid);Log.verboseln("WIFI_PASSWORD:%S", DeviceParamSave.wifi_password);Log.verboseln("SERVER_IP:%S", DeviceParamSave.server_ip);Log.verboseln("SERVER_PORT:%d", DeviceParamSave.server_port);if(Device_SaveParam() == STATUS_SUCCESS){// 成功响应wifi_send_state.state_id = ((wifi_receive_config.device_old_head - DeviceParamSave.device_head) << 4) + STATUS_SUCCESS;program_state.config_state_time = 0;program_state.run_state = RESET_STATE;  // 配置成功,重启节点Log.verboseln("config successful");Log.verboseln("switch reset state");}else{// 失败响应wifi_send_state.state_id = ((wifi_receive_config.device_old_head - DeviceParamSave.device_head) << 4) + STATUS_ERROR;Log.errorln("config fail");}}else{// 失败响应wifi_send_state.state_id = ((wifi_receive_config.device_old_head - DeviceParamSave.device_head) << 4) + STATUS_ERROR;Log.errorln("verify error");}}else{// 失败响应wifi_send_state.state_id = ((wifi_receive_config.device_old_head - DeviceParamSave.device_head) << 4) + STATUS_ERROR;Log.errorln("frame error");}// WiFi发送响应组包wifi_send_state.device_head = DeviceParamSave.device_head + FUNCTION_ID2;wifi_send_state.device_len = sizeof(SendState_t);wifi_send_state.device_id = DeviceParamSave.device_id;memcpy(&(wifi_send_state.software_version), &(DeviceParamSave.software_version), 15);memcpy(&(wifi_send_state.hardware_version), &(DeviceParamSave.hardware_version), 15);wifi_send_state.crc = check_crc16((uint8_t *)&wifi_send_state, wifi_send_state.device_len - 2);WIFI_send_data((char *)&wifi_send_state, wifi_send_state.device_len);}// 清除数据缓存memset(receive_data, 0, wifi_receive_config.device_len);  memset((char *)&wifi_send_state, 0, wifi_send_state.device_len);memset((char *)&wifi_receive_config, 0, wifi_receive_config.device_len);wifi_receive_flag = false;  // 处理完成后,方可接收WiFi新数据}
}

4.5、运行模式

只有在运行模式下,上位机才可以切换到配置模式、重启模式和升级模式,其他模式暂不支持远程控制模式切换。

运行模式下可周期上报节点数据,以及支持上位机控制继电器开关。

代码如下所示:

 /********************************************************************************** \brief  运行状态逻辑**** \param  无**** \retval 无********************************************************************************/
void Run_State(void)
{program_state.run_state_time++;// 处理WiFi接收的数据if(wifi_receive_flag == true){if(receive_data[0] == DeviceParamSave.device_head + FUNCTION_ID3){memcpy(&wifi_receive_mode_data, receive_data, sizeof(ReceiveData_Mode_t));if((wifi_receive_mode_data.device_head == (DeviceParamSave.device_head + FUNCTION_ID3)) && (wifi_receive_mode_data.device_id == (DeviceParamSave.device_id) || (wifi_receive_mode_data.device_id == 0XFFFF))){crc_temp = check_crc16((uint8_t *)&wifi_receive_mode_data, wifi_receive_mode_data.device_len - 2);if(wifi_receive_mode_data.crc == crc_temp){if(wifi_receive_mode_data.switch_mode == 0){program_state.run_state = RUN_STATE;Log.verboseln("keep run state");}else if(wifi_receive_mode_data.switch_mode == 1){RELAY_OFF;  // 进入配置模式,要断开继电器program_state.run_state = CONFIG_STATE;Log.verboseln("switch config state");}else if(wifi_receive_mode_data.switch_mode == 2){RELAY_OFF;  // 进入升级模式,要断开继电器program_state.run_state = UPDATA_STATE;Log.verboseln("switch updata state");}else if(wifi_receive_mode_data.switch_mode == 3){RELAY_OFF;  // 进入重启模式,要断开继电器program_state.run_state = RESET_STATE;Log.verboseln("switch reset state");}// 成功响应wifi_send_state.state_id = ((wifi_receive_mode_data.device_head - DeviceParamSave.device_head) << 4) + STATUS_SUCCESS;}else{// 失败响应wifi_send_state.state_id = ((wifi_receive_mode_data.device_head - DeviceParamSave.device_head) << 4) + STATUS_ERROR;Log.errorln("verify error");}}else{// 失败响应wifi_send_state.state_id = ((wifi_receive_mode_data.device_head - DeviceParamSave.device_head) << 4) + STATUS_ERROR;Log.errorln("frame error");}// WiFi发送响应组包wifi_send_state.device_head = DeviceParamSave.device_head + FUNCTION_ID2;wifi_send_state.device_len = sizeof(SendState_t);wifi_send_state.device_id = DeviceParamSave.device_id;memcpy(&(wifi_send_state.software_version), &(DeviceParamSave.software_version), 15);memcpy(&(wifi_send_state.hardware_version), &(DeviceParamSave.hardware_version), 15);wifi_send_state.crc = check_crc16((uint8_t *)&wifi_send_state, wifi_send_state.device_len - 2);WIFI_send_data((char *)&wifi_send_state, wifi_send_state.device_len);}if(receive_data[0] == DeviceParamSave.device_head + FUNCTION_ID5){memcpy(&wifi_receive_control_data, receive_data, sizeof(ReceiveData_Control_t));if((wifi_receive_control_data.device_head == (DeviceParamSave.device_head + FUNCTION_ID5)) && (wifi_receive_control_data.device_id == (DeviceParamSave.device_id) || (wifi_receive_control_data.device_id == 0XFFFF))){crc_temp = check_crc16((uint8_t *)&wifi_receive_control_data, wifi_receive_control_data.device_len - 2);if(wifi_receive_control_data.crc == crc_temp){if(wifi_receive_control_data.relay_state == 0){RELAY_OFF;}else{RELAY_ON;}// 成功响应wifi_send_state.state_id = ((wifi_receive_control_data.device_head - DeviceParamSave.device_head) << 4) + STATUS_SUCCESS;}else{// 失败响应wifi_send_state.state_id = ((wifi_receive_control_data.device_head - DeviceParamSave.device_head) << 4) + STATUS_ERROR;Log.errorln("verify error");}}else{// 失败响应wifi_send_state.state_id = ((wifi_receive_control_data.device_head - DeviceParamSave.device_head) << 4) + STATUS_ERROR;Log.errorln("frame error");}// WiFi发送响应组包wifi_send_state.device_head = DeviceParamSave.device_head + FUNCTION_ID2;wifi_send_state.device_len = sizeof(SendState_t);wifi_send_state.device_id = DeviceParamSave.device_id;memcpy(&(wifi_send_state.software_version), &(DeviceParamSave.software_version), 15);memcpy(&(wifi_send_state.hardware_version), &(DeviceParamSave.hardware_version), 15);wifi_send_state.crc = check_crc16((uint8_t *)&wifi_send_state, wifi_send_state.device_len - 2);WIFI_send_data((char *)&wifi_send_state, wifi_send_state.device_len);}// 清除数据缓存memset(receive_data, 0, wifi_receive_control_data.device_len);  memset((char *)&wifi_send_state, 0, wifi_send_state.device_len);memset((char *)&wifi_receive_mode_data, 0, wifi_receive_mode_data.device_len);memset((char *)&wifi_receive_control_data, 0, wifi_receive_control_data.device_len);wifi_receive_flag = false;  // 处理完成后,方可接收WiFi新数据}// 采集电压、电流和电耗,统计设备有效运行时间// 在逻辑上设定,采样时间要小于等于上传云端时间// 此项目中采样周期必须设定为1秒if((program_state.run_state_time % DeviceParamSave.sample_cycle) == 0){Updata_BL0942();wifi_send_data.voltage = getVoltage();     // 电压wifi_send_data.current = getCurrent();     // 电流wifi_send_data.power = getActivePower();   // 功率wifi_send_data.electricity = getEnergy();  // 电量if(wifi_send_data.power > 0.5)  // 功率大于0.5W,认为有负载{run_start_flag = true;  }else{run_start_flag = false; }}// 上传数据到服务器if(program_state.run_state_time >= (DeviceParamSave.upload_cycle * 1000)){program_state.run_state_time = 0;  // 上传周期时间要大于采样周期时间hours = run_time_ms / 3600000;minutes = (run_time_ms % 3600000) / 60000;seconds = (run_time_ms % 60000) / 1000;time_data = String(hours) + '-' + String(minutes) + '-' + String(seconds);memcpy(&(wifi_send_data.run_time), time_data.c_str(), time_data.length());for(uint8_t i = time_data.length(); i < 12; i++){wifi_send_data.run_time[i] = 0x00;}wifi_send_data.device_len = sizeof(SendData_t);wifi_send_data.crc = check_crc16((uint8_t *)&wifi_send_data, wifi_send_data.device_len - 2);WIFI_send_data((char *)&wifi_send_data, wifi_send_data.device_len);}
}

4.6、重启模式

确保缓存区数据都发送出去并且断开WiFi和服务器连接后节点重启。代码如下所示:

 /********************************************************************************** \brief  重启状态逻辑**** \param  无**** \retval 无********************************************************************************/
void Reset_State(void)
{if(tk_queue_empty(&send_dataqueue) == true)  // 确保发送缓存区的数据都发送后才可以重启{delay(3000);  // 重启节点的ACK可能还未发送出去,需要有延时DeInit_WIFI();ESP.restart();}
}

4.7、升级模式

当所有发送缓存区的数据都发送完成后,才可以执行升级功能。

目前升级仅支持局域网升级,升级前节点会发送升级的IP和端口给上位机。

升级超时时间默认设置为180秒,超时后节点切换到重启模式。

代码如下所示:

 /********************************************************************************** \brief  升级状态逻辑**** \param  无**** \retval 无********************************************************************************/
void Updata_State(void)
{static bool state_flag = false;if(Init_OTA() == STATUS_SUCCESS){if(state_flag == false){state_flag = true;// WiFi发送升级IP和端口wifi_send_updata.device_head = DeviceParamSave.device_head + FUNCTION_ID6;wifi_send_updata.device_len = sizeof(SendUpdata_t);wifi_send_updata.device_id = DeviceParamSave.device_id;memcpy(&(wifi_send_updata.software_version), &(DeviceParamSave.software_version), 15);memcpy(&(wifi_send_updata.hardware_version), &(DeviceParamSave.hardware_version), 15);memcpy(&(wifi_send_updata.updata_ip), ota_ip, strlen(ota_ip));wifi_send_updata.updata_port = OTA_PORT;wifi_send_updata.crc = check_crc16((uint8_t *)&wifi_send_updata, wifi_send_updata.device_len - 2);WIFI_send_data((char *)&wifi_send_updata, wifi_send_updata.device_len);memset((char *)&wifi_send_updata, 0, wifi_send_updata.device_len);}if(tk_queue_empty(&send_dataqueue) == true)  // 确保发送缓存区的数据都发送后才可以升级{OTA_updata();}}program_state.updata_state_time++;if(program_state.updata_state_time >= CYCLE_TIME_180SEC) {LED_OFF;program_state.updata_state_time = 0;program_state.run_state = RESET_STATE;Log.warningln("updata timeout");Log.warningln("switch reset state");}
}

5、程序功能特点

5.1、日志管理

下位机支持日志管理,可自定义串口打印不同等级的日志。

不过打印日志的串口和驱动BL0942的串口共用一路,所以在发布正式程序时,需要屏蔽日志打印功能。

日志管理部分代码如下所示:

 /********************************************************************************** \brief  初始化log日志模块**** \param  无**** \retval 无********************************************************************************/
void Init_Log(void)
{Serial.begin(4800, SERIAL_8N1);  // 4800bps 无校验Serial.println();Log.setPrefix(printPrefix); // set prefix similar to NLogLog.setSuffix(printSuffix); // set suffix Log.begin(LOG_LEVEL_VERBOSE, &Serial);Log.setShowLevel(false);    // Do not show loglevel, we will do this in the prefix#if LOG_OFFDeInit_Log();#endif
}

5.2、数据缓存队列

发送和接收数据支持FIFO缓存方式写入和读取数据,可自定义缓存区大小。

本项目中程序基本是顺序结构运行,不存在外部中断和定时任务对数据的干扰,并且发送和接收数据的数据量也不是很大,即使暂不使用FIFO缓存也可以满足使用要求。

数据缓存部分代码如下所示:

 /********************************************************************************** \brief  初始化数据缓存**** \param  无**** \retval 无********************************************************************************/
void Init_queue(void)
{// 清空缓冲区memset(send_dataqueue_pool, 0, SEND_DATAQUEUE_POOL_SIZE);memset(receive_dataqueue_pool, 0, RECEIVE_DATAQUEUE_POOL_SIZE);memset(serial_receive_dataqueue_pool, 0, SERIAL_RECEIVE_DATAQUEUE_POOL_SIZE);// 静态方式创建一个循环队列,存满不能再存tk_queue_init(&send_dataqueue, send_dataqueue_pool, sizeof(send_dataqueue_pool), sizeof(send_dataqueue_pool[0]), false);tk_queue_init(&receive_dataqueue, receive_dataqueue_pool, sizeof(receive_dataqueue_pool), sizeof(receive_dataqueue_pool[0]), false);tk_queue_init(&serial_receive_dataqueue, serial_receive_dataqueue_pool, sizeof(serial_receive_dataqueue_pool), sizeof(serial_receive_dataqueue_pool[0]), false);
}

相关文章:

ESP8266 WiFi物联网智能插座—下位机软件实现

目录 1、软件架构 2、开发环境 3、软件功能 4、程序设计 4.1、初始化 4.2、主循环状态机 4.3、初始化模式 4.4、配置模式 4.5、运行模式 4.6、重启模式 4.7、升级模式 5、程序功能特点 5.1、日志管理 5.2、数据缓存队列 本篇博文开始讲解下位机插座节点的MCU软件…...

微信小程序--下拉选择框组件封装,可CV直接使用

一、起因 接到的项目需求,查看ui设计图后,由于微信小程序官方设计的下拉选择框不符合需求,而且常用的第三方库也没有封装类似的,所以选择自己自定义组件。在此记录一下,方便日后复用。 ui设计图如下: 微信官方提供的选择框 对比发现并不能实现我们想要的功能。 二、自定义组件…...

代码随想录算法训练营第五十九天 |647. 回文子串、516.最长回文子序列、动态规划总结篇

一、647. 回文子串 题目链接/文章讲解&#xff1a;代码随想录 思考&#xff1a; 1.确定dp数组&#xff08;dp table&#xff09;以及下标的含义 如果本题定义dp[i] 为 下标i结尾的字符串有 dp[i]个回文串的话&#xff1a; 会发现很难找到递归关系&#xff0c;dp[i] 和 dp[i-1]…...

互联网性能和可用性优化CDN和DNS

当涉及到互联网性能和可用性优化时&#xff0c;DNS&#xff08;Domain Name System&#xff09;和CDN&#xff08;Content Delivery Network&#xff09;是两个至关重要的元素。它们各自发挥着关键作用&#xff0c;以确保用户能够快速、可靠地访问网站和应用程序。在本文中&…...

使用 ErrorStack 在出现报错 ORA-14402 时产生的日志量

0、测试结论&#xff1a; 测试结果&#xff1a;设置 ErrorStack 级别为 1 时产生 Trace 的日志量最小&#xff0c;大小为 308K&#xff0c;同时在 alert 日志中也存在记录。 1、准备测试数据&#xff1a; sqlplus / as sysdba show pdbs alter session set containerpdb; …...

详解Spring-ApplicationContext

加载器目前有两种选择&#xff1a;ContextLoaderListener和ContextLoaderServlet。 这两者在功能上完全等同&#xff0c;只是一个是基于Servlet2.3版本中新引入的Listener接口实现&#xff0c;而另一个基于Servlet接口实现。开发中可根据目标Web容器的实际情况进行选择。 配…...

关键字extern、static与const

关键字extern、static与const extern关键字与include的区别 extern:于声明某个函数或变量是外部的(其他源文件中)include:用于批量引入 项目中可以根据需要引入的函数或变量数量决定使用extern还是include static关键字 static关键字用于限制函数和全局变量的作用域仅在当…...

虹科方案|国庆出游季,古建筑振动监测让历史古迹不再受损

全文导读&#xff1a; 国庆长假即将到来&#xff0c;各位小伙伴是不是都做好了出游计划呢&#xff1f;今年中秋、国庆“双节”连休八天&#xff0c;多地预计游客接待量将创下新高&#xff0c;而各地的名胜古迹更是人流爆满。迎接游客的同时&#xff0c;如何保障历史古迹不因巨大…...

Python学习笔记-使用哈希算法Hash,Hashlib进行数据加密

文章目录 一、概述1.1 哈希算法1.2 常见算法分类1.2.1 SHA算法1.2.2 MD4算法1.2.3 MD5算法 1.3 Hash算法的特性1.4 Hash算法的应用场景1.4.1 数据校验1.4.2 安全加密1.4.3 数字签名 二、Hash算法使用2.1 使用hash函数直接获取hash值2.2 使用hashlib库进行hash计算2.2.1 基本使用…...

跨境电商能否成为黄河流域产业带的新引擎?

近年来&#xff0c;随着全球贸易格局的不断演变和中国经济的快速崛起&#xff0c;跨境电商已经成为中国外贸的一大亮点。而在中国国内&#xff0c;黄河流域产业带一直以其丰富的资源和悠久的历史而闻名&#xff0c;但也面临着转型升级的挑战。那么&#xff0c;跨境电商是否有潜…...

从数据到决策:企业投资信息查询API的关键作用

前言 在现代商业环境中&#xff0c;数据是一项无价的资产。企业不仅需要访问大量数据&#xff0c;还需要将这些数据转化为有用的见解&#xff0c;以支持战略决策。对于企业投资而言&#xff0c;准确的信息和实时的市场数据至关重要。在这个信息时代&#xff0c;企业投资信息查…...

NSIC2050JBT3G 车规级120V 50mA ±15% 用于LED照明的线性恒流调节器(CCR) 增强汽车安全

随着汽车行业的巨大变革&#xff0c;高品质的汽车氛围灯效、仪表盘等LED指示灯效已成为汽车内饰设计中不可或缺的元素。深力科安森美LED驱动芯片系列赋能智能座舱灯效充满艺术感和科技感——NSIC2050JBT3G LED驱动芯片&#xff0c;实现对每路LED亮度和颜色进行细腻控制&#xf…...

LuatOS-SOC接口文档(air780E)-- ftp - ftp 客户端

ftp.login(adapter,ip_addr,port,username,password)# FTP客户端 参数 传入值类型 解释 int 适配器序号, 只能是socket.ETH0, socket.STA, socket.AP,如果不填,会选择平台自带的方式,然后是最后一个注册的适配器 string ip_addr 地址 string port 端口,默认21 string…...

第二证券:市净率高好还是低好?

市净率是一个衡量公司股票投资价值的指标&#xff0c;通过比较公司股票价格和公司每股净资产的比值来评估公司股票的估值水平。市净率高好还是低好这个问题并没有一个简单的答案&#xff0c;取决于具体的市场环境和投资者的需求。本文将从多个角度分析市净率高好还是低好。 首…...

HTTP协议是什么

HTTP (全称为 “超文本传输协议”) 是一种应用非常广泛的 应用层协议&#xff0c;是一种网络通信协议。 超文本&#xff1a;所谓 “超文本” 的含义, 就是传输的内容不仅仅是文本(比如 html, css 这个就是文本), 还可以是一些其他的资源, 比如图片, 视频, 音频等二进制的数据。…...

微服务09-Sentinel的入门

文章目录 微服务中的雪崩现象解决办法&#xff1a;1. 超时处理2. 舱壁模式3. 熔断降级4.流量控制 Sentinel1.介绍2.使用操作3.限流规则4.实战&#xff1a;流量监控5.高级选项功能的使用1.关联模式2.链路模式3.总结 流控效果1.预热模式2.排队等待模式3.总结4.热点参数限流5.实战…...

2023-2024-1 高级语言程序设计实验一: 选择结构

7-1 古时年龄称谓知多少&#xff1f; 输入一个人的年龄&#xff08;岁&#xff09;&#xff0c;判断出他属于哪个年龄段 &#xff1f; 0-9 &#xff1a;垂髫之年&#xff1b; 10-19&#xff1a; 志学之年&#xff1b; 20-29 &#xff1a;弱冠之年&#xff1b; 30-39 &#…...

js事件循环详解

事件循环简介 JavaScript的事件循环是一种处理异步事件和回调函数的机制&#xff0c;它是在浏览器或Node.js环境中运行&#xff0c;用于管理任务队列和调用栈&#xff0c;以及在适当的时候执行回调函数。 事件循环的基本原理是&#xff0c;JavaScript引擎在空闲时等待事件的到…...

实战指南:使用 kube-prometheus-stack 监控 K3s 集群

作者简介 王海龙&#xff0c;Rancher 中国社区技术经理&#xff0c;Linux Foundation APAC Evangelist&#xff0c;负责 Rancher 中国技术社区的维护和运营。拥有 9 年的云计算领域经验&#xff0c;经历了 OpenStack 到 Kubernetes 的技术变革&#xff0c;无论底层操作系统 Lin…...

golang调用scws实现简易中文分词

1、安装 scws 官网以及文档 https://github.com/hightman/scws wget -q -O - http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2 | tar xjf -cd scws-1.2.3 ./configure --prefix/usr/local/scws --enable-shared make && make installLibraries have been ins…...

Excel 中使用数据透视图进行数据可视化

使用数据透视表&#xff08;PivotTable&#xff09;是在Excel中进行数据可视化的强大工具。下面将提供详细的步骤来使用数据透视表进行数据可视化。 **步骤一&#xff1a;准备数据** 首先&#xff0c;确保你有一个包含所需数据的Excel表格。数据应该按照一定的结构和格式组织…...

在SIP 语音呼叫中出现单通时要怎么解决?

在VoIP的环境中&#xff0c;特别是基于SIP通信的环境中&#xff0c;我们经常会遇到一些非常常见的问题&#xff0c;例如&#xff0c;单通&#xff0c;注册问题&#xff0c;回声&#xff0c;单通等。这些问题事实上都有非常直接的排查方式和解决办法&#xff0c;用户可以按照一定…...

【师兄啊师兄2】公布,李长寿成功渡劫,敖乙叛变,又一美女登场

Hello,小伙伴们&#xff0c;我是小郑继续为大家深度解析国漫资讯。 由玄机制作的师兄啊师兄第一季这才完结没有多久&#xff0c;没想到现在第二季就公布了&#xff0c;连海报和预告都出来了&#xff0c;看样子已经做得差不多了。预告看下来&#xff0c;能够明显感觉到官方又进步…...

视频倒着播放,原来是这么实现的

视频倒放是当今最流行的内容类型之一&#xff0c;这些视频服务于不同的目的&#xff0c;例如营销、娱乐、教育等。它们以独特的内容脱颖而出&#xff0c;并给观众留下深刻印象&#xff0c;将视频编辑带到了一个全新的水平。 在本文中&#xff0c;您将了解有关视频倒着播放的内…...

# 02 初识Verilog HDL

02 初识Verilog HDL ‍ 对于Verilog的语言的学习&#xff0c;我认为没必要一开始就从头到尾认真的学习这个语言&#xff0c;把这个语言所有细节都搞清楚也不现实&#xff0c;我们能够看懂当前FPGA的代码的程度就可以了&#xff0c;随着学习FPGA深度的增加&#xff0c;再不断的…...

使用 Eziriz .NET Reactor 对c#程序加密

我目前测试过好几个c#加密软件。效果很多时候是加密后程序执行错误&#xff0c;或者字段找不到的现象 遇到这个加密软件用了一段时间都很正常&#xff0c;分享一下使用流程 破解版本自行百度。有钱的支持正版&#xff0c;我用的是 Eziriz .NET Reactor 6.8.0 第一步 安装 Ezi…...

Restclient-cpp库介绍和实际应用:爬取www.sohu.com

概述 Restclient-cpp是一个用C编写的简单而优雅的RESTful客户端库&#xff0c;它可以方便地发送HTTP请求和处理响应。它基于libcurl和jsoncpp&#xff0c;支持GET, POST, PUT, PATCH, DELETE, HEAD等方法&#xff0c;以及自定义HTTP头部&#xff0c;超时设置&#xff0c;代理服…...

提升市场调研和竞品分析效率:利用Appium实现App数据爬取

市场调研和竞品分析通常需要获取大量的数据&#xff0c;而手动收集这些数据往往耗时且容易出错。而利用Appium框架&#xff0c;我们可以轻松地实现自动化的App数据爬取&#xff0c;这种方法不仅可以节省时间和人力成本&#xff0c;还可以提高数据的准确性和一致性。 Appium是一…...

【Git笔记】之Git重命名详解

目录 一、Git重命名文件 二、Git重命名origin 三、Git重命名分支 四、Git重命名远程分支 五、Git重命名作者 六、Git clone重命名 七、Git重命名仓库 八、Git重命名文件夹后出现两个代码 九、Git重命名文件名 Git是一个非常流行的版本控制工具&#xff0c;它可以帮助程…...

201、RabbitMQ 之 Exchange 典型应用模型 之 工作队列(Work Queue)

目录 ★ 工作队列介绍代码演示测试注意点1&#xff1a;注意点2&#xff1a; ★ 工作队列介绍 工作队列&#xff1a; 就是让多个消费者竞争消费同一个消息队列的消息&#xff0c;相当于多个消费者共享消息队列。 ▲ RabbitMQ可以让多个消费者竞争消费同一个消息队列 ▲ 消息队…...