This commit is contained in:
j3d1 2021-06-25 18:08:50 +02:00 committed by Eleon
parent 8ffae0b66f
commit 3098c8f1ab
2 changed files with 54 additions and 50 deletions

View file

@ -21,6 +21,7 @@
#include "lux.h" #include "lux.h"
#define SNTP_SERVERS "0.pool.ntp.org", "1.pool.ntp.org", \ #define SNTP_SERVERS "0.pool.ntp.org", "1.pool.ntp.org", \
"2.pool.ntp.org", "3.pool.ntp.org" "2.pool.ntp.org", "3.pool.ntp.org"
@ -252,7 +253,7 @@ void user_init(void) {
sdk_wifi_set_opmode(wifi_mode); sdk_wifi_set_opmode(wifi_mode);
if(wifi_sta_enable) { if(wifi_sta_enable) {
printf("try STA Mode\n"); printf("try STA Mode: %s %s\n", wifi_sta_ssid, wifi_sta_password);
struct sdk_station_config config; struct sdk_station_config config;
strcpy((char *) config.ssid, wifi_sta_ssid); strcpy((char *) config.ssid, wifi_sta_ssid);
strcpy((char *) config.password, wifi_sta_password); strcpy((char *) config.password, wifi_sta_password);
@ -289,7 +290,7 @@ void user_init(void) {
} }
if(wifi_ap_enable) { if(wifi_ap_enable) {
printf("try AP Mode\n"); printf("try AP Mode: %s %s\n", wifi_ap_ssid, wifi_ap_password);
/* Read and validate paramenters. */ /* Read and validate paramenters. */
int8_t wifi_ap_ssid_hidden = 0; int8_t wifi_ap_ssid_hidden = 0;
sysparam_get_int8("wifi_ap_ssid_hidden", &wifi_ap_ssid_hidden); sysparam_get_int8("wifi_ap_ssid_hidden", &wifi_ap_ssid_hidden);
@ -402,12 +403,12 @@ void user_init(void) {
/* turn off LED */ /* turn off LED */
//gpio_enable(LED_PIN, GPIO_OUTPUT); //gpio_enable(LED_PIN, GPIO_OUTPUT);
//gpio_write(LED_PIN, true); //gpio_write(LED_PIN, true);
xTaskCreate(&lux_task, "lux_task", 256, NULL, 2, NULL); xTaskCreate(&lux_task, "lux_task", 256, NULL, 1, NULL);
/* initialize tasks */ /* initialize tasks */
xTaskCreate(&httpd_task, "&httpd_task", 2048, NULL, 2, NULL); xTaskCreate(&httpd_task, "httpd_task", 2048, NULL, 3, NULL);
xTaskCreate(&sntp_task, "SNTP", 512, NULL, 1, NULL); xTaskCreate(&sntp_task, "SNTP", 512, NULL, 2, NULL);
} }
>>>>>>> 4b8d354 (basic webconf) >>>>>>> 4b8d354 (basic webconf)
} }

View file

@ -11,9 +11,12 @@
#include <string.h> #include <string.h>
#include <FreeRTOS.h> #include <FreeRTOS.h>
#include <task.h> #include <task.h>
extern "C" { extern "C" {
#include <sysparam.h> #include <sysparam.h>
#include <lwipopts.h>
} }
#include <espressif/esp_common.h> #include <espressif/esp_common.h>
#include <lwip/tcp.h> #include <lwip/tcp.h>
@ -31,9 +34,10 @@ struct {
} has_changed; } has_changed;
void websocket_task(void *pvParameter) { void websocket_task(void *pvParameter) {
struct tcp_pcb *pcb = (struct tcp_pcb *) pvParameter; auto *pcb = (struct tcp_pcb *) pvParameter;
int connstarttime = xTaskGetTickCount(); size_t connstarttime = xTaskGetTickCount();
has_changed = {true, true, true};
for (;;) { for (;;) {
if(pcb == NULL || pcb->state != ESTABLISHED) { if(pcb == NULL || pcb->state != ESTABLISHED) {
@ -44,7 +48,7 @@ void websocket_task(void *pvParameter) {
//Global Info //Global Info
if(has_changed.global) { if(has_changed.global) {
struct timeval tv; timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
int uptime = xTaskGetTickCount() * portTICK_PERIOD_MS / 1000; int uptime = xTaskGetTickCount() * portTICK_PERIOD_MS / 1000;
int heap = (int) xPortGetFreeHeapSize(); int heap = (int) xPortGetFreeHeapSize();
@ -79,7 +83,7 @@ void websocket_task(void *pvParameter) {
//Connection Info //Connection Info
if(has_changed.connection) { if(has_changed.connection) {
struct timeval tv; timeval tv;
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
int connuptime = (xTaskGetTickCount() - connstarttime) * portTICK_PERIOD_MS / 1000; int connuptime = (xTaskGetTickCount() - connstarttime) * portTICK_PERIOD_MS / 1000;
@ -104,7 +108,6 @@ void websocket_task(void *pvParameter) {
vTaskDelayMs(2000); vTaskDelayMs(2000);
} }
if(has_changed.wifi) { if(has_changed.wifi) {
uint8_t opmode = sdk_wifi_get_opmode(); uint8_t opmode = sdk_wifi_get_opmode();
const char *opmode_str = "??"; const char *opmode_str = "??";
@ -136,7 +139,7 @@ void websocket_task(void *pvParameter) {
if(opmode == SOFTAP_MODE || opmode == STATIONAP_MODE) { if(opmode == SOFTAP_MODE || opmode == STATIONAP_MODE) {
uint8_t hwaddr[6]; uint8_t hwaddr[6];
sdk_wifi_get_macaddr(SOFTAP_IF, hwaddr); sdk_wifi_get_macaddr(SOFTAP_IF, hwaddr);
struct ip_info info; ip_info info;
sdk_wifi_get_ip_info(SOFTAP_IF, &info); sdk_wifi_get_ip_info(SOFTAP_IF, &info);
char *apssid = NULL; char *apssid = NULL;
@ -168,7 +171,7 @@ void websocket_task(void *pvParameter) {
if(opmode == STATION_MODE || opmode == STATIONAP_MODE) { if(opmode == STATION_MODE || opmode == STATIONAP_MODE) {
uint8_t hwaddr[6]; uint8_t hwaddr[6];
sdk_wifi_get_macaddr(STATION_IF, hwaddr); sdk_wifi_get_macaddr(STATION_IF, hwaddr);
struct ip_info info; ip_info info;
sdk_wifi_get_ip_info(STATION_IF, &info); sdk_wifi_get_ip_info(STATION_IF, &info);
char *stassid = NULL; char *stassid = NULL;
sysparam_get_string("wifi_sta_ssid", &stassid); sysparam_get_string("wifi_sta_ssid", &stassid);