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"
#define SNTP_SERVERS "0.pool.ntp.org", "1.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);
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;
strcpy((char *) config.ssid, wifi_sta_ssid);
strcpy((char *) config.password, wifi_sta_password);
@ -289,7 +290,7 @@ void user_init(void) {
}
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. */
int8_t wifi_ap_ssid_hidden = 0;
sysparam_get_int8("wifi_ap_ssid_hidden", &wifi_ap_ssid_hidden);
@ -402,12 +403,12 @@ void user_init(void) {
/* turn off LED */
//gpio_enable(LED_PIN, GPIO_OUTPUT);
//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 */
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)
}

View file

@ -11,9 +11,12 @@
#include <string.h>
#include <FreeRTOS.h>
#include <task.h>
extern "C" {
#include <sysparam.h>
#include <lwipopts.h>
}
#include <espressif/esp_common.h>
#include <lwip/tcp.h>
@ -31,9 +34,10 @@ struct {
} has_changed;
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 (;;) {
if(pcb == NULL || pcb->state != ESTABLISHED) {
@ -43,8 +47,8 @@ void websocket_task(void *pvParameter) {
//Global Info
if(has_changed.global){
struct timeval tv;
if(has_changed.global) {
timeval tv;
gettimeofday(&tv, NULL);
int uptime = xTaskGetTickCount() * portTICK_PERIOD_MS / 1000;
int heap = (int) xPortGetFreeHeapSize();
@ -57,14 +61,14 @@ void websocket_task(void *pvParameter) {
/* Generate response in JSON format */
char response[160];
size_t len = snprintf(response, sizeof(response),
"{\"walltime\" : \"%d\","
"\"uptime\" : \"%d\","
" \"heap\" : \"%d\","
" \"chipid\" : \"%08x\","
" \"flashid\" : \"0x%08x\","
" \"flashsize\" : \"%u\","
" \"hostname\" : \"%s\""
"}", (int) tv.tv_sec, uptime, heap, chip_id, flash_id, flash_size, hostname);
"{\"walltime\" : \"%d\","
"\"uptime\" : \"%d\","
" \"heap\" : \"%d\","
" \"chipid\" : \"%08x\","
" \"flashid\" : \"0x%08x\","
" \"flashsize\" : \"%u\","
" \"hostname\" : \"%s\""
"}", (int) tv.tv_sec, uptime, heap, chip_id, flash_id, flash_size, hostname);
free(hostname);
if(len < sizeof(response)) {
LOCK_TCPIP_CORE();
@ -78,23 +82,23 @@ void websocket_task(void *pvParameter) {
//Connection Info
if(has_changed.connection){
struct timeval tv;
if(has_changed.connection) {
timeval tv;
gettimeofday(&tv, NULL);
int connuptime = (xTaskGetTickCount() - connstarttime) * portTICK_PERIOD_MS / 1000;
printf("conn %d: "
IPSTR
" <-> "
IPSTR
" \n", pcb->netif_idx, IP2STR(&pcb->local_ip), IP2STR(&pcb->remote_ip));
IPSTR
" <-> "
IPSTR
" \n", pcb->netif_idx, IP2STR(&pcb->local_ip), IP2STR(&pcb->remote_ip));
char response[160];
size_t len = snprintf(response, sizeof(response),
"{\"connage\" : \"%d\","
"\"clientip\" : \""
IPSTR
"\""
"}", connuptime, IP2STR(&pcb->remote_ip));
"{\"connage\" : \"%d\","
"\"clientip\" : \""
IPSTR
"\""
"}", connuptime, IP2STR(&pcb->remote_ip));
if(len < sizeof(response)) {
LOCK_TCPIP_CORE();
websocket_write(pcb, (unsigned char *) response, len, WS_TEXT_MODE);
@ -104,8 +108,7 @@ void websocket_task(void *pvParameter) {
vTaskDelayMs(2000);
}
if(has_changed.wifi){
if(has_changed.wifi) {
uint8_t opmode = sdk_wifi_get_opmode();
const char *opmode_str = "??";
switch (opmode) {
@ -136,7 +139,7 @@ void websocket_task(void *pvParameter) {
if(opmode == SOFTAP_MODE || opmode == STATIONAP_MODE) {
uint8_t hwaddr[6];
sdk_wifi_get_macaddr(SOFTAP_IF, hwaddr);
struct ip_info info;
ip_info info;
sdk_wifi_get_ip_info(SOFTAP_IF, &info);
char *apssid = NULL;
@ -145,15 +148,15 @@ void websocket_task(void *pvParameter) {
/* Generate response in JSON format */
char response[128];
size_t len = snprintf(response, sizeof(response),
"{\"opmode\" : \"%s\","
" \"apssid\" : \"%s\","
" \"apip\" : \""
IPSTR
"\","
" \"apmac\" : \""
MACSTR
"\""
"}", opmode_str, apssid, IP2STR(&info.ip), MAC2STR(hwaddr));
"{\"opmode\" : \"%s\","
" \"apssid\" : \"%s\","
" \"apip\" : \""
IPSTR
"\","
" \"apmac\" : \""
MACSTR
"\""
"}", opmode_str, apssid, IP2STR(&info.ip), MAC2STR(hwaddr));
free(apssid);
if(len < sizeof(response)) {
LOCK_TCPIP_CORE();
@ -168,7 +171,7 @@ void websocket_task(void *pvParameter) {
if(opmode == STATION_MODE || opmode == STATIONAP_MODE) {
uint8_t hwaddr[6];
sdk_wifi_get_macaddr(STATION_IF, hwaddr);
struct ip_info info;
ip_info info;
sdk_wifi_get_ip_info(STATION_IF, &info);
char *stassid = NULL;
sysparam_get_string("wifi_sta_ssid", &stassid);
@ -176,15 +179,15 @@ void websocket_task(void *pvParameter) {
/* Generate response in JSON format */
char response[128];
size_t len = snprintf(response, sizeof(response),
"{\"opmode\" : \"%s\","
" \"stassid\" : \"%s\","
" \"staip\" : \""
IPSTR
"\","
" \"stamac\" : \""
MACSTR
"\""
"}", opmode_str, stassid, IP2STR(&info.ip), MAC2STR(hwaddr));
"{\"opmode\" : \"%s\","
" \"stassid\" : \"%s\","
" \"staip\" : \""
IPSTR
"\","
" \"stamac\" : \""
MACSTR
"\""
"}", opmode_str, stassid, IP2STR(&info.ip), MAC2STR(hwaddr));
free(stassid);
if(len < sizeof(response)) {
LOCK_TCPIP_CORE();