kopia lustrzana https://github.com/martin-ger/esp_mqtt
Added basic sample at user_basic/
rodzic
ede97ea37b
commit
10f292f27e
2
Makefile
2
Makefile
|
@ -43,7 +43,7 @@ LIB_MODULES = mqtt
|
|||
LIBS = c gcc hal pp phy net80211 lwip wpa main
|
||||
|
||||
# compiler flags using during compilation of source files
|
||||
CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -DUSE_OPTIMIZE_PRINTF
|
||||
CFLAGS = -Os -g -O2 -Wpointer-arith -Wundef -Werror -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH -DUSE_OPTIMIZE_PRINTF
|
||||
#-DMQTT_DEBUG_ON
|
||||
|
||||
# linker flags used to generate the main object file
|
||||
|
|
|
@ -31,16 +31,18 @@ in the user_init() function.
|
|||
# Building and Flashing
|
||||
The code can be used in any project that is compiled using the NONOS_SDK or the esp-open-sdk. Also the sample code in the user directory can be build using the standard SDKs after adapting the variables in the Makefile.
|
||||
|
||||
If you don't need the full demo program, you can find a minimal demo in the directory "user_basic". Rename it to "user", adapt "user_config.h", and do the "make" to build a small demo that just starts an MQTT broker.
|
||||
|
||||
Build the esp_uMQTT_broker firmware with "make". "make flash" flashes it onto an esp8266.
|
||||
|
||||
If you want to use the precompiled binaries from the firmware directory you can flash them on an ESP12 with
|
||||
If you want to use the precompiled binaries of the bigger demo (see below) from the firmware directory you can flash them on an ESP12 with
|
||||
|
||||
```bash
|
||||
esptool.py --port /dev/ttyUSB0 write_flash -fs 32m 0x00000 firmware/0x00000.bin 0x10000 firmware/0x10000.bin
|
||||
```
|
||||
|
||||
# Usage
|
||||
In the user directory there is a demo program that serves as a stand-alone MQTT broker. The program starts with the following default configuration:
|
||||
In the user directory there is a demo program that serves as a stand-alone MQTT broker and bridge. The program starts with the following default configuration:
|
||||
- ssid: ssid, password: password
|
||||
- ap_ssid: MyAP, ap_password: none, ap_on: 1, ap_open: 1
|
||||
- network: 192.168.4.0/24
|
||||
|
|
|
@ -10,7 +10,6 @@ typedef enum {SIG_DO_NOTHING=0, SIG_START_SERVER=1, SIG_SEND_DATA, SIG_UART0, SI
|
|||
#define WIFI_AP_PASSWORD "none"
|
||||
|
||||
#define MAX_CLIENTS 8
|
||||
#define MAX_DHCP 8
|
||||
|
||||
//
|
||||
// Here the MQTT stuff
|
||||
|
@ -33,11 +32,6 @@ typedef enum {SIG_DO_NOTHING=0, SIG_START_SERVER=1, SIG_SEND_DATA, SIG_UART0, SI
|
|||
#define MAX_CON_SEND_SIZE 1024
|
||||
#define MAX_CON_CMD_SIZE 80
|
||||
|
||||
//
|
||||
// Define this if you have a status LED connected to a GPIO pin
|
||||
//
|
||||
#define STATUS_LED_GIPO 2
|
||||
|
||||
//
|
||||
// Define this to support the "scan" command for AP search
|
||||
//
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef __MQTT_CONFIG_H__
|
||||
#define __MQTT_CONFIG_H__
|
||||
|
||||
/*DEFAULT CONFIGURATIONS*/
|
||||
|
||||
#define MQTT_PORT 1883
|
||||
#define MQTT_BUF_SIZE 1024
|
||||
#define MQTT_KEEPALIVE 120 /*second*/
|
||||
#define MQTT_RECONNECT_TIMEOUT 5 /*seconds*/
|
||||
|
||||
#define MQTT_MAX_SUBSCRIPTIONS 30
|
||||
#define MQTT_MAX_RETAINED_TOPICS 30
|
||||
|
||||
|
||||
#define TCP_MAX_CONNECTIONS 10
|
||||
#define STA_SSID "SSID"
|
||||
#define STA_PASS "PASSWD"
|
||||
|
||||
|
||||
#define PROTOCOL_NAMEv31 /*MQTT version 3.1 compatible with Mosquitto v0.15*/
|
||||
//PROTOCOL_NAMEv311 /*MQTT version 3.11 compatible with https://eclipse.org/paho/clients/testing/*/
|
||||
|
||||
typedef enum {SIG_DO_NOTHING=0, SIG_UART0, SIG_CONSOLE_RX, SIG_CONSOLE_TX} USER_SIGNALS;
|
||||
|
||||
#endif // __MQTT_CONFIG_H__
|
|
@ -0,0 +1,28 @@
|
|||
#include "user_interface.h"
|
||||
#include "mqtt_server.h"
|
||||
#include "user_config.h"
|
||||
|
||||
void ICACHE_FLASH_ATTR user_init()
|
||||
{
|
||||
struct station_config stationConf;
|
||||
|
||||
// Initialize the UART
|
||||
uart_div_modify(0, UART_CLK_FREQ / 115200);
|
||||
|
||||
os_printf("\r\n\r\nMQTT Broker starting\r\n", espconn_tcp_get_max_con());
|
||||
|
||||
// Setup STA
|
||||
wifi_set_opmode(STATIONAP_MODE);
|
||||
stationConf.bssid_set = 0;
|
||||
os_strcpy(&stationConf.ssid, STA_SSID);
|
||||
os_strcpy(&stationConf.password, STA_PASS);
|
||||
wifi_station_set_config(&stationConf);
|
||||
wifi_station_set_auto_connect(1);
|
||||
|
||||
// Allow larger number of TCP (=MQTT) clients
|
||||
espconn_tcp_set_max_con(TCP_MAX_CONNECTIONS);
|
||||
os_printf("Max number of TCP clients: %d\r\n", espconn_tcp_get_max_con());
|
||||
|
||||
//Start MQTT broker
|
||||
MQTT_server_start(MQTT_PORT, MQTT_MAX_SUBSCRIPTIONS, MQTT_MAX_RETAINED_TOPICS);
|
||||
}
|
Ładowanie…
Reference in New Issue