added logging and broker config

pull/16/head
Martin Ger 2017-08-19 15:01:53 +02:00
rodzic a6078d3caa
commit ec02aba72a
8 zmienionych plików z 56 dodań i 20 usunięć

Wyświetl plik

@ -28,22 +28,25 @@ After reboot it will connect to your home router and itself is ready for station
The console understands the following commands:
Basic commands (enough to get it working in nearly all environments):
General commands:
- help: prints a short help message
- set [ssid|password] _value_: changes the settings for the uplink AP (WiFi config of your home-router)
- set ap_on [0|1]: selects, whether the soft-AP is disabled (ap_on=0) or enabled (ap_on=1, default)
- set [ap_ssid|ap_password] _value_: changes the settings for the soft-AP of the ESP (for your stations)
- show [config|stats|script|mqtt]: prints the current config or some status information and statistics
- save: saves the current config parameters to flash
- set broker_user _unsername_: sets the username for authentication of MQTT clients ("none" if no auth, default)
- set broker_password _password_: sets the password for authentication of MQTT clients ("none" if empty, default)
- lock [_password_]: saves and locks the current config, changes are not allowed. Password can be left open if already set before
- unlock _password_: unlocks the config, requires password from the lock command
- reset [factory]: resets the esp, 'factory' optionally resets WiFi params to default values (works on a locked device only from serial console)
- set speed [80|160]: sets the CPU clock frequency (default 80 Mhz)
- set config_port _portno_: sets the port number of the console login (default is 7777, 0 disables remote console config)
- set config_access _mode_: controls the networks that allow config access (0: no access, 1: only internal, 2: only external, 3: both (default))
- quit: terminates a remote session
Advanced commands (most of the set-commands are effective only after save and reset):
WiFi and network related commands:
- set [ssid|password] _value_: changes the settings for the uplink AP (WiFi config of your home-rou- set [ap_ssid|ap_password] _value_: changes the settings for the soft-AP of the ESP (for your stations)ter)
- set ap_on [0|1]: selects, whether the soft-AP is disabled (ap_on=0) or enabled (ap_on=1, default)
- set ap_open [0|1]: selects, whether the soft-AP uses WPA2 security (ap_open=0, automatic, if an ap_password is set) or open (ap_open=1)
- set auto_connect [0|1]: selects, whether the WiFi client should automatically retry to connect to the uplink AP (default: on=1)
- set network _ip-addr_: sets the IP address of the internal network, network is always /24, router is always x.x.x.1
- set dns _dns-addr_: sets a static DNS address
- set dns dhcp: configures use of the dynamic DNS address from DHCP, default
@ -52,14 +55,18 @@ Advanced commands (most of the set-commands are effective only after save and re
- set netmask _netmask_: sets a static netmask for the uplink network
- set gw _gw-addr_: sets a static gateway address in the uplink network
- scan: does a scan for APs
- set ap_open [0|1]: selects, whether the soft-AP uses WPA2 security (ap_open=0, automatic, if an ap_password is set) or open (ap_open=1)
- set speed [80|160]: sets the CPU clock frequency (default 80 Mhz)
- set config_port _portno_: sets the port number of the console login (default is 7777, 0 disables remote console config)
- set config_access _mode_: controls the networks that allow config access (0: no access, 1: only internal, 2: only external, 3: both (default))
- script [_portno_|delete]: opens port for upload of scripts or deletes the current script
While the user interface looks similar to my esp_wifi_repeater at https://github.com/martin-ger/esp_wifi_repeater this does NO NAT routing. AP and STA network are stricly separated and there is no routing in between. The only possible connection via both networks is the uMQTT broker that listens on both interfaces.
MQTT broker related command:
- set broker_user _unsername_: sets the username for authentication of MQTT clients ("none" if no auth, default)
- set broker_password _password_: sets the password for authentication of MQTT clients ("none" if empty, default)
- set broker_subscriptions _max_: sets the max number of subscription the broker can store (default: 30)
- set broker_retained_messages _max_: sets the max number of retained messages the broker can store (default: 30)
- set script_logging [0|1]: switches logging of script execution on or off (not permanently stored in the configuration)
- script [_portno_|delete]: opens port for upload of scripts or deletes the current script
# MQTT client/bridging functionality
The broker comes with a "local" and a "remote" client, which means, the broker itself can publish and subscribe topics. The "local" client is a client to the own broker (without the need of an additional TCP connection).

Plik binarny nie jest wyświetlany.

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -35,6 +35,8 @@ void config_load_default(sysconfig_p config) {
config->config_port = CONSOLE_SERVER_PORT;
config->config_access = LOCAL_ACCESS | REMOTE_ACCESS;
config->max_subscriptions = 30;
config->max_retained_messages = 30;
os_sprintf(config->mqtt_broker_user, "%s", "none");
config->mqtt_broker_password[0] = 0;

Wyświetl plik

@ -47,6 +47,8 @@ typedef struct
uint16_t config_port; // Port on which the concole listenes (0 if no access)
uint8_t config_access; // Controls the interfaces that allow config access (default LOCAL_ACCESS | REMOTE_ACCESS)
uint16_t max_subscriptions; // Upper limit of subscribed topics
uint16_t max_retained_messages; // Upper limit of stored retained messages
uint8_t mqtt_broker_user[32]; // Username for client login, "none" if empty
uint8_t mqtt_broker_password[32]; // Password for client login

Wyświetl plik

@ -11,9 +11,9 @@
#include "easygpio.h"
#endif
#define lang_debug //os_printf
//bool lang_logging = true;
//#define lang_log(...) {if (lang_logging){char log_buffer[256]; os_sprintf (log_buffer, "%s: ", get_timestr()); con_print(log_buffer); os_sprintf (log_buffer, __VA_ARGS__); con_print(log_buffer);}}
#define lang_log //os_printf
#define lang_log(...) {if (lang_logging){char log_buffer[256]; os_sprintf (log_buffer, "%s: ", get_timestr()); con_print(log_buffer); os_sprintf (log_buffer, __VA_ARGS__); con_print(log_buffer);}}
//#define lang_log //os_printf
extern uint8_t *my_script;
extern void do_command(char *t1, char *t2, char *t3);
@ -48,6 +48,7 @@ typedef struct _gpio_entry_t {
static gpio_entry_t gpios[MAX_GPIOS];
#endif
bool lang_logging = false;
char **my_token;
int max_token;
bool script_enabled = false;

Wyświetl plik

@ -5,6 +5,8 @@
extern MQTT_Client mqttClient;
extern bool mqtt_enabled, mqtt_connected;
extern bool lang_logging;
uint8_t tmp_buffer[128];
uint32_t loop_time;

Wyświetl plik

@ -364,7 +364,7 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn) {
if (strcmp(tokens[0], "help") == 0) {
os_sprintf(response,
"show [config|stats|mqtt|script]\r\n|set [ssid|password|auto_connect|ap_ssid|ap_password|network|dns|ip|netmask|gw|ap_on|ap_open|speed|config_port|config_access|broker_user|broker_password] <val>\r\n|quit|save [config]|reset [factory]|lock [<password>]|unlock <password>");
"show [config|stats|mqtt|script]\r\n|set [ssid|password|auto_connect|ap_ssid|ap_password|network|dns|ip|netmask|gw|ap_on|ap_open|speed|config_port|config_access|broker_subscriptions|broker_retained_messages|broker_user|broker_password] <val>\r\n|quit|save [config]|reset [factory]|lock [<password>]|unlock <password>");
to_console(response);
#ifdef SCRIPTED
os_sprintf(response, "|script <port>");
@ -422,9 +422,12 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn) {
to_console(response);
#endif
os_sprintf(response, "MQTT broker max. subscription: %d\r\nMQTT broker max. retained messages: %d\r\n",
config.max_subscriptions, config.max_retained_messages);
to_console(response);
if (os_strcmp(config.mqtt_broker_user, "none") != 0) {
os_sprintf(response,
"MQTT broker username: %s password: %s\r\n",
"MQTT broker username: %s\r\nMQTT broker password: %s\r\n",
config.mqtt_broker_user,
config.locked ? "***" : (char *)config.mqtt_broker_password);
to_console(response);
@ -435,7 +438,7 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn) {
if (os_strcmp(config.mqtt_host, "none") != 0) {
os_sprintf(response,
"MQTT host: %s\r\nMQTT port: %d\r\nMQTT user: %s\r\nMQTT password: %s\r\nMQTT id: %s\r\n",
"MQTT client host: %s\r\nMQTT client port: %d\r\nMQTT client user: %s\r\nMQTT client password: %s\r\nMQTT client id: %s\r\n",
config.mqtt_host, config.mqtt_port, config.mqtt_user,
config.locked ? "***" : (char *)config.mqtt_password, config.mqtt_id);
to_console(response);
@ -878,6 +881,18 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn) {
goto command_handled;
}
#endif
if (strcmp(tokens[1], "broker_subscriptions") == 0) {
config.max_subscriptions = atoi(tokens[2]);
os_sprintf(response, "Broker subscriptions set\r\n");
goto command_handled;
}
if (strcmp(tokens[1], "broker_retained_messages") == 0) {
config.max_retained_messages = atoi(tokens[2]);
os_sprintf(response, "Broker retained messages set\r\n");
goto command_handled;
}
if (strcmp(tokens[1], "broker_user") == 0) {
os_strncpy(config.mqtt_broker_user, tokens[2], 32);
config.mqtt_broker_user[31] = '\0';
@ -895,6 +910,13 @@ void ICACHE_FLASH_ATTR console_handle_command(struct espconn *pespconn) {
os_sprintf(response, "Broker password set\r\n");
goto command_handled;
}
#ifdef SCRIPTED
if (strcmp(tokens[1], "script_logging") == 0) {
lang_logging = atoi(tokens[2]);
os_sprintf(response, "Script logging set\r\n");
goto command_handled;
}
#endif
#ifdef NTP
if (strcmp(tokens[1], "ntp_server") == 0) {
os_strncpy(config.ntp_server, tokens[2], 32);
@ -1406,8 +1428,8 @@ void user_init() {
MQTT_local_onData(MQTT_local_DataCallback);
MQTT_server_onAuth(mqtt_broker_auth);
MQTT_server_start(1883 /*port */ , 30 /*max_subscriptions */ ,
30 /*max_retained_items */ );
MQTT_server_start(1883 /*port */ , config.max_subscriptions,
config.max_retained_messages);
//Start task
system_os_task(user_procTask, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen);