implemented AP on/off control
This commit is contained in:
parent
c6035b15d7
commit
7a032ac452
|
|
@ -56,7 +56,7 @@
|
|||
#define SCRATCH_BUFSIZE 4096
|
||||
#define AUTH_DATA_MAX_LENGTH 16
|
||||
|
||||
#define HTTP_SERVER_DEBUG_LEVEL 1
|
||||
#define HTTP_SERVER_DEBUG_LEVEL 0
|
||||
|
||||
typedef enum
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,123 +1,126 @@
|
|||
/* Copyright 2022 Bogdan Pilyugin
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* File name: NetTransport.h
|
||||
* Project: ChargePointMainboard
|
||||
* Created on: 2022-07-21
|
||||
* Author: Bogdan Pilyugin
|
||||
* Description:
|
||||
*/
|
||||
|
||||
#ifndef MAIN_INCLUDE_NETTRANSPORT_H_
|
||||
#define MAIN_INCLUDE_NETTRANSPORT_H_
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "mqtt_client.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_wifi_types.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char imei[32];
|
||||
char imsi[32];
|
||||
char oper[32];
|
||||
char model[32];
|
||||
} MODEM_INFO;
|
||||
|
||||
#define ETH_PRIO 100
|
||||
#define STA_PRIO 50
|
||||
#define PPP_PRIO 30
|
||||
#define AP_PRIO 10
|
||||
|
||||
//#define DEFAULT_FALLBACK_DNS "8.8.8.8"
|
||||
|
||||
//QueueHandle_t MQTT1MessagesQueueHandle;
|
||||
//QueueHandle_t MQTT2MessagesQueueHandle;
|
||||
//EventGroupHandle_t transport_event_group;
|
||||
|
||||
wifi_ap_record_t* GetWiFiAPRecord(uint8_t n);
|
||||
|
||||
void StartTimeGet(void);
|
||||
|
||||
//void WiFiAPStart(void);
|
||||
//void WiFiSTAStart(void);
|
||||
//void WiFiAPSTAStart(void);
|
||||
void WiFiStart(void);
|
||||
void WiFiDisconnect(void);
|
||||
void WiFiScan(void);
|
||||
void EthStart(void);
|
||||
|
||||
void WiFiTransportTask(void *prm);
|
||||
|
||||
|
||||
void PPPModemColdStart(void);
|
||||
void PPPModemSoftRestart(void);
|
||||
void PPPModemStart(void);
|
||||
|
||||
int PPPModemGetRSSI(void);
|
||||
void ModemSendSMS(void);
|
||||
void ModemSendAT(char *cmd, char *resp, int timeout);
|
||||
|
||||
void MQTTRun(void);
|
||||
|
||||
MODEM_INFO* GetPPPModemInfo(void);
|
||||
esp_mqtt_client_handle_t* GetMQTTHandle(void);
|
||||
void MQTTStart(void);
|
||||
void MQTTStop(void);
|
||||
void MQTTReconnect(void);
|
||||
|
||||
esp_netif_t* GetPPPNetifAdapter(void);
|
||||
esp_netif_t* GetSTANetifAdapter(void);
|
||||
esp_netif_t* GetAPNetifAdapter(void);
|
||||
esp_netif_t* GetETHNetifAdapter(void);
|
||||
|
||||
bool isWIFIConnected(void);
|
||||
bool isETHConnected(void);
|
||||
bool isPPPConnected(void);
|
||||
bool isLORAConnected(void);
|
||||
|
||||
bool GetMQTT1Connected(void);
|
||||
bool GetMQTT2Connected(void);
|
||||
|
||||
|
||||
void SetDefaultNetIF(esp_netif_t *IF);
|
||||
void NextDefaultNetIF(void);
|
||||
void PrintDefaultNetIF(void);
|
||||
void GetDefaultNetIFName(char *name);
|
||||
|
||||
void PrintNetifs(void);
|
||||
void GotEthIF(void);
|
||||
|
||||
void GetRFC3339Time(char *t);
|
||||
void StartTimeGet(void);
|
||||
|
||||
esp_err_t StartOTA(void);
|
||||
char* GetAvailVersion();
|
||||
char* GetUpdateStatus();
|
||||
|
||||
void StartSystemTimer(void);
|
||||
uint32_t GetUpTime(void);
|
||||
|
||||
void RegEthReset(void (*eth_rst)(uint8_t level));
|
||||
void RegGSMReset(void (*gsm_rst)(uint8_t level));
|
||||
|
||||
void GenerateSystemSettingsJSONFile(void);
|
||||
void mDNSServiceStart(void);
|
||||
|
||||
#endif /* MAIN_INCLUDE_NETTRANSPORT_H_ */
|
||||
/* Copyright 2022 Bogdan Pilyugin
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* File name: NetTransport.h
|
||||
* Project: ChargePointMainboard
|
||||
* Created on: 2022-07-21
|
||||
* Author: Bogdan Pilyugin
|
||||
* Description:
|
||||
*/
|
||||
|
||||
#ifndef MAIN_INCLUDE_NETTRANSPORT_H_
|
||||
#define MAIN_INCLUDE_NETTRANSPORT_H_
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "mqtt_client.h"
|
||||
#include "esp_netif.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_wifi_types.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char imei[32];
|
||||
char imsi[32];
|
||||
char oper[32];
|
||||
char model[32];
|
||||
} MODEM_INFO;
|
||||
|
||||
#define ETH_PRIO 100
|
||||
#define STA_PRIO 50
|
||||
#define PPP_PRIO 30
|
||||
#define AP_PRIO 10
|
||||
|
||||
//#define DEFAULT_FALLBACK_DNS "8.8.8.8"
|
||||
|
||||
//QueueHandle_t MQTT1MessagesQueueHandle;
|
||||
//QueueHandle_t MQTT2MessagesQueueHandle;
|
||||
//EventGroupHandle_t transport_event_group;
|
||||
|
||||
wifi_ap_record_t* GetWiFiAPRecord(uint8_t n);
|
||||
|
||||
void StartTimeGet(void);
|
||||
|
||||
//void WiFiAPStart(void);
|
||||
//void WiFiSTAStart(void);
|
||||
//void WiFiAPSTAStart(void);
|
||||
void WiFiStart(void);
|
||||
void WiFiDisconnect(void);
|
||||
void WiFiScan(void);
|
||||
void WiFiStop();
|
||||
void WiFiStopAP();
|
||||
void WiFiStartAP();
|
||||
void EthStart(void);
|
||||
|
||||
void WiFiTransportTask(void *prm);
|
||||
|
||||
|
||||
void PPPModemColdStart(void);
|
||||
void PPPModemSoftRestart(void);
|
||||
void PPPModemStart(void);
|
||||
|
||||
int PPPModemGetRSSI(void);
|
||||
void ModemSendSMS(void);
|
||||
void ModemSendAT(char *cmd, char *resp, int timeout);
|
||||
|
||||
void MQTTRun(void);
|
||||
|
||||
MODEM_INFO* GetPPPModemInfo(void);
|
||||
esp_mqtt_client_handle_t* GetMQTTHandle(void);
|
||||
void MQTTStart(void);
|
||||
void MQTTStop(void);
|
||||
void MQTTReconnect(void);
|
||||
|
||||
esp_netif_t* GetPPPNetifAdapter(void);
|
||||
esp_netif_t* GetSTANetifAdapter(void);
|
||||
esp_netif_t* GetAPNetifAdapter(void);
|
||||
esp_netif_t* GetETHNetifAdapter(void);
|
||||
|
||||
bool isWIFIConnected(void);
|
||||
bool isETHConnected(void);
|
||||
bool isPPPConnected(void);
|
||||
bool isLORAConnected(void);
|
||||
|
||||
bool GetMQTT1Connected(void);
|
||||
bool GetMQTT2Connected(void);
|
||||
|
||||
|
||||
void SetDefaultNetIF(esp_netif_t *IF);
|
||||
void NextDefaultNetIF(void);
|
||||
void PrintDefaultNetIF(void);
|
||||
void GetDefaultNetIFName(char *name);
|
||||
|
||||
void PrintNetifs(void);
|
||||
void GotEthIF(void);
|
||||
|
||||
void GetRFC3339Time(char *t);
|
||||
void StartTimeGet(void);
|
||||
|
||||
esp_err_t StartOTA(void);
|
||||
char* GetAvailVersion();
|
||||
char* GetUpdateStatus();
|
||||
|
||||
void StartSystemTimer(void);
|
||||
uint32_t GetUpTime(void);
|
||||
|
||||
void RegEthReset(void (*eth_rst)(uint8_t level));
|
||||
void RegGSMReset(void (*gsm_rst)(uint8_t level));
|
||||
|
||||
void GenerateSystemSettingsJSONFile(void);
|
||||
void mDNSServiceStart(void);
|
||||
|
||||
#endif /* MAIN_INCLUDE_NETTRANSPORT_H_ */
|
||||
|
|
|
|||
|
|
@ -270,6 +270,22 @@ static HTTP_IO_RESULT HTTPPostAdaptersSettings(httpd_req_t *req, char *PostData)
|
|||
}
|
||||
}
|
||||
|
||||
if (httpd_query_key_value(PostData, "wifistart", tmp, 4) == ESP_OK)
|
||||
{
|
||||
if (!strcmp(tmp, (const char*) "prs"))
|
||||
{
|
||||
WiFiStartAP();
|
||||
}
|
||||
}
|
||||
if (httpd_query_key_value(PostData, "wifistop", tmp, 4) == ESP_OK)
|
||||
{
|
||||
if (!strcmp(tmp, (const char*) "prs"))
|
||||
{
|
||||
WiFiStopAP();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (httpd_query_key_value(PostData, "wifisave", tmp, 4) == ESP_OK)
|
||||
{
|
||||
if (!strcmp(tmp, (const char*) "prs"))
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ static const char *TAG = "WiFiTransport";
|
|||
#define EXAMPLE_ESP_WIFI_CHANNEL 6
|
||||
#define EXAMPLE_MAX_STA_CONN 10
|
||||
|
||||
static bool isWiFiRunning = false;
|
||||
static bool isWiFiConnected = false;
|
||||
static bool isWiFiGotIp = false;
|
||||
static bool isWiFiFail = false;
|
||||
|
|
@ -503,8 +504,9 @@ static void WiFiControlTask(void *arg)
|
|||
xTaskCreate(wifi_init_apsta, "InitSoftAPSTATask", 1024 * 4, (void*) 0, 3, NULL);
|
||||
break;
|
||||
}
|
||||
isWiFiRunning = true;
|
||||
//WiFi in work service
|
||||
while (1)
|
||||
while (isWiFiRunning)
|
||||
{
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
if (isWiFiConnected)
|
||||
|
|
@ -530,6 +532,15 @@ static void WiFiControlTask(void *arg)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isWiFiConnected)
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_wifi_disconnect());
|
||||
}
|
||||
ESP_ERROR_CHECK(esp_wifi_stop());
|
||||
ESP_ERROR_CHECK(esp_wifi_deinit());
|
||||
esp_netif_destroy(ap_netif);
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void WiFiStart(void)
|
||||
|
|
@ -537,6 +548,28 @@ void WiFiStart(void)
|
|||
xTaskCreate(WiFiControlTask, "WiFiCtrlTask", 1024 * 4, (void*) 0, 3, NULL);
|
||||
}
|
||||
|
||||
void WiFiStop()
|
||||
{
|
||||
isWiFiRunning = false;
|
||||
}
|
||||
|
||||
void WiFiStopAP()
|
||||
{
|
||||
if (GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_APSTA || GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_STA)
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
else
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
|
||||
}
|
||||
void WiFiStartAP()
|
||||
{
|
||||
if (GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_APSTA)
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_APSTA));
|
||||
else if (GetSysConf()->wifiSettings.WiFiMode == WIFI_MODE_STA)
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
else
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_AP));
|
||||
}
|
||||
|
||||
static void wifi_scan(void *arg)
|
||||
{
|
||||
uint16_t number = DEFAULT_SCAN_LIST_SIZE;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user