148 lines
4.3 KiB
C
148 lines
4.3 KiB
C
/* WiFi station Example
|
|
|
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
|
|
|
Unless required by applicable law or agreed to in writing, this
|
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
CONDITIONS OF ANY KIND, either express or implied.
|
|
*/
|
|
#include <string.h>
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "freertos/event_groups.h"
|
|
#include "esp_system.h"
|
|
#include "esp_wifi.h"
|
|
#include "esp_event.h"
|
|
#include "esp_log.h"
|
|
#include "nvs_flash.h"
|
|
#include "lwip/err.h"
|
|
#include "lwip/sys.h"
|
|
#include <stdio.h>
|
|
#include "driver/ledc.h"
|
|
#include "esp_err.h"
|
|
#include "can_network.h"
|
|
#include "freertos/queue.h"
|
|
#include "esp_check.h"
|
|
#include "soc/rtc.h"
|
|
#include "driver/mcpwm.h"
|
|
|
|
/*蓝牙相关的头文件*/
|
|
#include "esp_bt.h"
|
|
#include "driver/uart.h"
|
|
#include "esp_gap_ble_api.h"
|
|
#include "esp_gatts_api.h"
|
|
#include "esp_bt_defs.h"
|
|
#include "esp_bt_main.h"
|
|
|
|
/* The examples use WiFi configuration that you can set via project configuration menu
|
|
|
|
If you'd rather not, just change the below entries to strings with
|
|
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
|
|
*/
|
|
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
|
|
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
|
|
#define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
|
|
|
#if CONFIG_ESP_WIFI_AUTH_OPEN
|
|
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
|
|
#elif CONFIG_ESP_WIFI_AUTH_WEP
|
|
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
|
|
#elif CONFIG_ESP_WIFI_AUTH_WPA_PSK
|
|
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
|
|
#elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
|
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
|
#elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK
|
|
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
|
#elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK
|
|
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
|
|
#elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK
|
|
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
|
|
#elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK
|
|
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
|
|
#endif
|
|
|
|
/* FreeRTOS event group to signal when we are connected*/
|
|
//static EventGroupHandle_t s_wifi_event_group;
|
|
|
|
/* The event group allows multiple bits for each event, but we only care about two events:
|
|
* - we are connected to the AP with an IP
|
|
* - we failed to connect after the maximum amount of retries */
|
|
#define WIFI_CONNECTED_BIT BIT0
|
|
#define WIFI_FAIL_BIT BIT1
|
|
#define GPIO_4G_PWR GPIO_NUM_4
|
|
|
|
static const char *TAG = "main";
|
|
|
|
//static int s_retry_num = 0;
|
|
|
|
extern void wifi_init_softap(void);
|
|
|
|
void ads1220_init(void);
|
|
void PWR_4G_Init(void);
|
|
extern void can_init(void);
|
|
extern void FLOW_init();
|
|
extern void DEPTH_init();
|
|
extern void BL0939_init(void);
|
|
extern void ads1220_task_start(void);
|
|
extern void ModBusTCPSlave_init(void);
|
|
extern esp_err_t i2c_master_init(void);
|
|
extern void config_load(void);
|
|
extern void uart0_modbus_slave_init(void);
|
|
extern void bt_client_init(void);
|
|
//extern void ESP32_Uart_Receive_Data(void);
|
|
uint32_t rtc_clk_apb_freq;
|
|
|
|
void app_main(void)
|
|
{
|
|
// Initialize NVS
|
|
esp_err_t ret = nvs_flash_init();
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND)
|
|
{
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
ret = nvs_flash_init();
|
|
}
|
|
ESP_ERROR_CHECK(ret);
|
|
ESP_ERROR_CHECK(i2c_master_init());
|
|
config_load();
|
|
ESP_LOGI(TAG, "ESP_WIFI_MODE_STA");
|
|
rtc_clk_apb_freq = rtc_clk_apb_freq_get();
|
|
ESP_LOGI(TAG, "rtc_clk_apb_freq=%d", rtc_clk_apb_freq);
|
|
|
|
wifi_init_softap();//ok
|
|
// wifi_init_sta();
|
|
// can_init();
|
|
|
|
PWR_4G_Init();
|
|
ModBusTCPSlave_init();
|
|
|
|
ads1220_task_start();
|
|
BL0939_init();
|
|
DEPTH_init();
|
|
FLOW_init();
|
|
|
|
uart0_modbus_slave_init();
|
|
|
|
bt_client_init();//ok
|
|
//ESP32_Uart_Receive_Data();
|
|
|
|
}
|
|
|
|
void PWR_4G_Init(void)
|
|
{
|
|
// zero-initialize the config structure.
|
|
gpio_config_t io_conf = {};
|
|
// disable interrupt
|
|
io_conf.intr_type = GPIO_INTR_DISABLE;
|
|
// set as output mode
|
|
io_conf.mode = GPIO_MODE_OUTPUT;
|
|
// bit mask of the pins that you want to set,e.g.GPIO18/19
|
|
io_conf.pin_bit_mask = GPIO_4G_PWR;
|
|
// disable pull-down mode
|
|
io_conf.pull_down_en = 0;
|
|
// disable pull-up mode
|
|
io_conf.pull_up_en = 0;
|
|
// configure GPIO with the given settings
|
|
gpio_config(&io_conf);
|
|
|
|
gpio_set_level(GPIO_4G_PWR, 0);
|
|
} |