tuanpmt / esp_mqtt Goto Github PK
View Code? Open in Web Editor NEWMQTT client library for ESP8266
Home Page: http://tuanpm.net/post/esp_mqtt/
License: MIT License
MQTT client library for ESP8266
Home Page: http://tuanpm.net/post/esp_mqtt/
License: MIT License
Hello,
I compiled the firmware with my changed configurations in user_config.h and left the CFG_HOLDER unchanged(CFG_HOLDER 0x00FF55A4).
I then flashed the firmware and opened up the serial monitor.
This is the result:
what am I doing wrong?
Serial Results:
load ...
MQTT_InitConnection
MQTT_InitClient
WIFI_INIT
System started ...
mode : sta(18:fe:34:9d:5f:71)
add if0
STATION_IDLE
STATION_IDLE
STATION_IDLE
scandone
no DVES_HOME found, reconnect after 1s
STATION_IDLE
STATION_IDLE
reconnect
STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
scandone
no DVES_HOME found, reconnect after 1s
STATION_IDLE
STATION_IDLE
reconnect
Hi,
Compiled OK and flashed OK.
When running, I get on the ESP8266 side endless repetition of :
TCP: Connect to ip 192.168.0.92:1883
TCP:Reconect to: 192.168.0.92:1883
TCP: Reconnect to 192.168.0.92:1883
When I check Mosquitto log, I see repetition of :
New connection from 192.168.0.31 on port 1883.
Mosquitto socket error on client (null) disconnecting
Any suggestion ???
Thanks.
Hi! I'm trying to switch from nodemcu to this firmware...but i really can't understand how to use serial... can you please provide a basic example to send (and receive) mqtt messages from serial?
I have not been able to get an SSL connection to work between the esp8266 and mosquitto running on Ubuntu 14.04. Is SSL really working? If so, what steps are needed?
I am using the HEAD of the master branch and compiling with esp-open-sdk+esp_iot_sdk_v0.9.5.
I set DEFAULT_SECURITY to 1 in user_config.h.
I also instrumented the code to confirm that that the espconn_secure* functions are called.
I have tried using 512, 1000, 1024, and 2048 bit SSL certs on the server.
I think the options for compiling release and debug versions are wrong, instead of
ifeq ($(FLAVOR),debug)
CFLAGS += -g -O2
LDFLAGS += -g -O2
endif
ifeq ($(FLAVOR),release)
CFLAGS += -g -O0
LDFLAGS += -g -O0
endif
it should be
ifeq ($(FLAVOR),debug)
CFLAGS += -g -O0
LDFLAGS += -g -O0
endif
ifeq ($(FLAVOR),release)
CFLAGS += -g -O2
LDFLAGS += -g -O2
endif
Using exactly the example, just changed in user_config.h:
I got no call to mqttConnectedCb. The INFO("MQTT: Connected\r\n"); in mqttConnectedCb is never displayed!
The broker receives the keep alive but nothing else: neither publishes nor subscribes.
There is no warning at complie time neither at flashing operation.
Here is the console log result
dhcp client start...
STATION_IDLE
STATION_IDLE
ip:192.168.1.44,mask:255.255.255.0,gw:192.168.1.254
TCP: Connect to ip 192.168.1.41:1883
MQTT: Connected to broker 192.168.1.41:1883
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: Disconnected callback
MQTT: Disconnected
Free memory
TCP: Connect to ip 192.168.1.41:1883
TCP: Reconnect to: 192.168.1.41:1883
MQTT: Connected to broker 192.168.1.41:1883
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: Disconnected callback
MQTT: Disconnected
Free memory
TCP: Connect to ip 192.168.1.41:1883
TCP: Reconnect to: 192.168.1.41:1883
MQTT: Connected to broker 192.168.1.41:1883
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: Disconnected callback
MQTT: Disconnected
Free memory
TCP: Connect to ip 192.168.1.41:1883
TCP: Reconnect to: 192.168.1.41:1883
MQTT: Connected to broker 192.168.1.41:1883
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: Disconnected callback
MQTT: Disconnected
Free memory
TCP: Connect to ip 192.168.1.41:1883
TCP: Reconnect to: 192.168.1.41:1883
MQTT: Connected to broker 192.168.1.41:1883
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: Disconnected callback
MQTT: Disconnected
Free memory
TCP: Connect to ip 192.168.1.41:1883
TCP: Reconnect to: 192.168.1.41:1883
MQTT: Connected to broker 192.168.1.41:1883
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: Disconnected callback
MQTT: Disconnected
This is endlessly repeating.
Hello,
I've been testing my mqtt network in a local network with fixed ip, but i have a dhcp server in a apache running in this network and i would like to know if is there a way to find the broker machine just with hostname in this LAN.
tks.
I just finish installing esp8266 tool-chain and try to get familiar with your esp_mqtt. so this is my very first program I compile and flash to the esp-07 module. the flashing was a success but i having an issue connecting to my mosquitto mqtt broker running on rasberry pi 2. the following message constantly display in serial terminal. could you help take a look on my issue ?. BTW. i just install mosquitto on my ubantu with the same procedure as the one installed on rasberry pi. there is no issue at all to connect so I'm not sure what causing this.
TCP: Connect to ip 172.16.1.22:1880
TCP: Reconnect to: 172.16.1.22:1880
MQTT: Connected to broker 172.16.1.22:1880
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: data received 4 bytes
MQTT: Connected to 172.16.1.22:1880
MQTT: Connected
MQTT: queue subscribe, topic"/mqtt/topic/0", id: 21
MQTT: queue subscribe, topic"/mqtt/topic/1", id: 22
MQTT: queue subscribe, topic"/mqtt/topic/2", id: 23
MQTT: queuing publish, length: 23, queue size(646/2048)
MQTT: queuing publish, length: 25, queue size(671/2048)
MQTT: queuing publish, length: 25, queue size(698/2048)
TCP: Disconnected callback
MQTT: Disconnected
Free memory
I was using esp-open-sdk ( https://github.com/pfalcon/esp-open-sdk ) and was getting this error:
make SDK_BASE="/home/pi/esp/esp-open-sdk" FLAVOR="release" all
CC driver/uart.c
CC mqtt/mqtt.c
CC mqtt/ringbuf.c
CC mqtt/mqtt_msg.c
CC mqtt/queue.c
CC mqtt/proto.c
CC mqtt/utils.c
CC user/user_main.c
CC modules/config.c
CC modules/wifi.c
AR build/app_app.a
LD build/app.out
/home/pi/esp/esp-open-sdk/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: cannot open linker script file /home/pi/esp/esp-open-sdk/ld/eagle.app.v6.ld: No such file or directory
collect2: error: ld returned 1 exit status
Makefile:184: recipe for target 'build/app.out' failed
make: *** [build/app.out] Error 1
Might be an idea to put the BLANKER stuff into the linux Makefile too. Took me a while to work that one out :)
Like so:
Receive topic: /topic, data: test
rm match
TCP: Reconnect to mosquitto:8000
reconnect
scandone
add 0
aid 2
cnt
connected with Markey, channel 10
Seems to happen every 20-30 messages received.
Hi,
I commented out the CLIENT_SSL_ENABLE line. I changed the port to 1883 and the ESP8266 does not connect correctly to a local MQTT server.
The serial output from the terminal window shows
load ...
MQTT_InitConnection
MQTT_InitClient
WIFI_INIT
System started ...
mode : sta(18:fe:34:98:d5:69)
add if0
scandone
STATION_IDLE
add 0
aid 1
pm open phy_2,type:2 0 0
cnt
connected with betgear, channel 2
dhcp client start...
STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
STATION_IDLE
ip:192.168.1.47,mask:255.255.255.0,gw:192.168.1.1
TCP: Connect to ip 192.168.1.147:1883
MQTT: subscribe, topic"/test/topic" at broker 192.168.1.147:1883
MQTT: subscribe, topic"/test2/topic" at broker 192.168.1.147:1883
client handshake start.
TCP: Reconnect to 192.168.1.147:1883
TCP: Connect to ip 192.168.1.147:1883
TCP:Reconect to: 192.168.1.147:1883
client handshake start.
This is constantly repeating. Whilst the verbose output from Mosquitto shows
1420304463: New connection from 192.168.1.47 on port 1883.
1420304463: Socket error on client (null), disconnecting.
1420304469: New connection from 192.168.1.47 on port 1883.
1420304469: Socket error on client (null), disconnecting.
1420304475: New connection from 192.168.1.47 on port 1883.
1420304475: Socket error on client (null), disconnecting.
Any help appreciated.
Glen.
This great but I can not get a library MQTT cope with OTA in the make file "ERROR build / app.out1 section.irom0.text 'will not fit in the region
irom0_0_seg' 'if you can show your solution.
Hi
I managed to install the new version of your MQTT software thanks. However, one you install one version you cannot then install another one. The .bin files are being generated and apparently uploaded correctly.
I think that there's a problem in the makefile.
Your earlier version 'flash_ota_boot' had this:-
and your new one does this:-
I suspect that this is the code for the cloud update version which would, I guess be loaded into flash and verified before the restart vector was set to avoid corrupting the software if there was a transmission error.
I'm guessing that what's happening is that the current makefile is just dumping subsequent software updates into flash into a location relative to the previous one but not changing the restart vector - instead of putting it on top of the bootloader?
Maybe!
Hi
Two of us on two completely separate systems have updated to your new code. Firstly once you compile and flash a chip - next time you compile and flash, there is no difference even though the BIN files have been updated. Something wrong there. I can guarantee that the ESP-01 will not be getting the update even though it looks as it it has programmed.
Secondly when we power up with the updated software, we don't seem to get the little progress dots any more,. That is as far as we have gone.
there is a
system_os_post(MQTT_TASK_PRIO, 0, (os_param_t)client);
missing in the code that sends a keepalive message (in mqtt_timer)
Hello, I installed sdk from there (https://github.com/pfalcon/esp-open-sdk and change the VENDOR_SDK = 0.9.4 ), compile with make STANDALONE=n . If I try to compile the code I get this error.
ystrem@ystrem-PC:~/esp_mqtt$ make
CC driver/uart.c
CC user/config.c
CC user/mqtt.c
CC user/mqtt_msg.c
CC user/str_queue.c
CC user/user_main.c
CC user/utils.c
CC user/wifi.c
AR build/app_app.a
LD build/app.out
build/app_app.a(mqtt.o): In function `MQTT_InitClient':
/home/ystrem/esp_mqtt/user/mqtt.c:524: undefined reference to `espconn_secure_connect'
/home/ystrem/esp_mqtt/user/mqtt.c:529: undefined reference to `espconn_secure_connect'
build/app_app.a(mqtt.o): In function `mqtt_tcpclient_recon_cb':
/home/ystrem/esp_mqtt/user/mqtt.c:374: undefined reference to `espconn_secure_disconnect'
build/app_app.a(mqtt.o): In function `mqtt_tcpclient_recv':
/home/ystrem/esp_mqtt/user/mqtt.c:158: undefined reference to `espconn_secure_disconnect'
/home/ystrem/esp_mqtt/user/mqtt.c:278: undefined reference to `espconn_secure_connect'
build/app_app.a(mqtt.o): In function `mqtt_tcpclient_connect_cb':
/home/ystrem/esp_mqtt/user/mqtt.c:350: undefined reference to `espconn_secure_connect'
build/app_app.a(mqtt.o): In function `MQTT_Publish':
/home/ystrem/esp_mqtt/user/mqtt.c:382: undefined reference to `espconn_secure_sent'
build/app_app.a(mqtt.o): In function `MQTT_Subscribe':
/home/ystrem/esp_mqtt/user/mqtt.c:397: undefined reference to `espconn_secure_sent'
/home/ystrem/esp_mqtt/user/mqtt.c:403: undefined reference to `espconn_secure_sent'
build/app_app.a(mqtt.o): In function `MQTT_Task':
/home/ystrem/esp_mqtt/user/mqtt.c:416: undefined reference to `espconn_secure_sent'
collect2: error: ld returned 1 exit status
make: *** [build/app.out] Error 1
The strange thing is that, if I try to compile nathan`s code (which is using your library) everything is ok.
(https://github.com/nathanchantrell/esp_mqtt_oled)
ystrem@ystrem-PC:~/esp_mqtt_oled$ make
CC driver/i2c.c
CC driver/i2c_oled.c
CC driver/uart.c
CC user/config.c
CC user/mqtt.c
CC user/mqtt_msg.c
CC user/user_main.c
CC user/utils.c
AR build/app_app.a
LD build/app.out
FW firmware/0x00000.bin
FW firmware/0x40000.bin
Here is my Makefile
# Changelog
# Changed the variables to include the header file directory
# Added global var for the XTENSA tool root
#
# This make file still needs some work.
#
#
# Output directors to store intermediate compiled files
# relative to the project directory
BUILD_BASE = build
FW_BASE = firmware
# Base directory for the compiler
#XTENSA_TOOLS_ROOT ?= /opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin
XTENSA_TOOLS_ROOT ?= ../esp-open-sdk/xtensa-lx106-elf/bin
# base directory of the ESP8266 SDK package, absolute
#SDK_BASE ?= /opt/Espressif/ESP8266_SDK
SDK_BASE ?= ../esp-open-sdk/sdk/
#Esptool.py path and port
ESPTOOL ?= ../esp-open-sdk/esptool/esptool.py
ESPPORT ?= /dev/ttyUSB1
# name for the target project
TARGET = app
# which modules (subdirectories) of the project to include in compiling
MODULES = driver user
EXTRA_INCDIR = include $(SDK_BASE)/../include
# libraries used in this project, mainly provided by the SDK
LIBS = c gcc hal phy pp net80211 lwip wpa upgrade 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
# linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
# linker script used for the above linkier step
LD_SCRIPT = eagle.app.v6.ld
# various paths from the SDK used in this project
SDK_LIBDIR = lib
SDK_LDDIR = ld
SDK_INCDIR = include include/json
# we create two different files for uploading into the flash
# these are the names and options to generate them
FW_FILE_1 = 0x00000
FW_FILE_1_ARGS = -bo $@ -bs .text -bs .data -bs .rodata -bc -ec
FW_FILE_2 = 0x40000
FW_FILE_2_ARGS = -es .irom0.text $@ -ec
# select which tools to use as compiler, librarian and linker
CC := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
AR := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-ar
LD := $(XTENSA_TOOLS_ROOT)/xtensa-lx106-elf-gcc
####
#### no user configurable options below here
####
FW_TOOL ?= esptool
SRC_DIR := $(MODULES)
BUILD_DIR := $(addprefix $(BUILD_BASE)/,$(MODULES))
SDK_LIBDIR := $(addprefix $(SDK_BASE)/,$(SDK_LIBDIR))
SDK_INCDIR := $(addprefix -I$(SDK_BASE)/,$(SDK_INCDIR))
SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.c))
OBJ := $(patsubst %.c,$(BUILD_BASE)/%.o,$(SRC))
LIBS := $(addprefix -l,$(LIBS))
APP_AR := $(addprefix $(BUILD_BASE)/,$(TARGET)_app.a)
TARGET_OUT := $(addprefix $(BUILD_BASE)/,$(TARGET).out)
LD_SCRIPT := $(addprefix -T$(SDK_BASE)/$(SDK_LDDIR)/,$(LD_SCRIPT))
INCDIR := $(addprefix -I,$(SRC_DIR))
EXTRA_INCDIR := $(addprefix -I,$(EXTRA_INCDIR))
MODULE_INCDIR := $(addsuffix /include,$(INCDIR))
FW_FILE_1 := $(addprefix $(FW_BASE)/,$(FW_FILE_1).bin)
FW_FILE_2 := $(addprefix $(FW_BASE)/,$(FW_FILE_2).bin)
V ?= $(VERBOSE)
ifeq ("$(V)","1")
Q :=
vecho := @true
else
Q := @
vecho := @echo
endif
vpath %.c $(SRC_DIR)
define compile-objects
$1/%.o: %.c
$(vecho) "CC $$<"
$(Q) $(CC) $(INCDIR) $(MODULE_INCDIR) $(EXTRA_INCDIR) $(SDK_INCDIR) $(CFLAGS) -c $$< -o $$@
endef
.PHONY: all checkdirs clean
all: checkdirs $(TARGET_OUT) $(FW_FILE_1) $(FW_FILE_2)
$(FW_FILE_1): $(TARGET_OUT)
$(vecho) "FW $@"
$(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_1_ARGS)
$(FW_FILE_2): $(TARGET_OUT)
$(vecho) "FW $@"
$(Q) $(FW_TOOL) -eo $(TARGET_OUT) $(FW_FILE_2_ARGS)
$(TARGET_OUT): $(APP_AR)
$(vecho) "LD $@"
$(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@
$(APP_AR): $(OBJ)
$(vecho) "AR $@"
$(Q) $(AR) cru $@ $^
checkdirs: $(BUILD_DIR) $(FW_BASE)
$(BUILD_DIR):
$(Q) mkdir -p $@
firmware:
$(Q) mkdir -p $@
flash: firmware/0x00000.bin firmware/0x40000.bin
$(ESPTOOL) --port $(ESPPORT) write_flash 0x00000 firmware/0x00000.bin 0x40000 firmware/0x40000.bin
test:
screen $(ESPPORT) 115200
clean:
$(Q) rm -f $(APP_AR)
$(Q) rm -f $(TARGET_OUT)
$(Q) rm -rf $(BUILD_DIR)
$(Q) rm -rf $(BUILD_BASE)
$(Q) rm -f $(FW_FILE_1)
$(Q) rm -f $(FW_FILE_2)
$(Q) rm -rf $(FW_BASE)
$(foreach bdir,$(BUILD_DIR),$(eval $(call compile-objects,$(bdir))))
Thanks
As shown here: https://www.youtube.com/watch?v=WbQs_7WIUEs, is it possible to add OTA support in makefile?
So, I've bodged the makefile from your previous incarnation of the MQTT software and I can now successfully compile and re-compile it.
However, once it's logged onto my MQTT server and subscribed to the test messages it just sits there doing nothing!
If I send an MQTT message to one of it's topics, it doesn;t respond and if I send any serial data it doesn't respond either.
I think that this has great potential though.
I've thought a lot about it and when you get it further developed it would be great to have a consistent set of messages:- something like
Send
MQTT::
response
OK
or
or
SUBSCRIBE:
response
OK
or
FAIL
When the wifi has connected and the MQTT server has connected maybe a simple message like
READY
I was thinking about how you might connect a newly installed ESP module and perhaps if GPIO2 is held to ground at power up, you could generate a WiFi AP with the SSID as the MAC number of the module.
A simple config web page would then give the following:-
AP SSID and password.
MQTT server URL and port number
MQTT server user and password
An outgoing data topic if required
An incoming data topic if required
Display the units MAC number
This would allow anyone to connect to a new unit with a phone or tablet to configure it.
I can see applications for this in home automation. My friend Peter Scargill and I are designing home automation devices and we've been using NRF24L01 radio modules and ATMEL RF processors with a lightweight mesh.
However, I think that ESP modules with MQTT software is far more useful.
I'd be happy to give you a few mains control units to play with when we get the PCBs finished and integrated with your MQTT software
Regards
Aidan
PS This is the current version of my mains switching unit with a 10 amp relay and a DS1802 temperature sensor
Coming from web development, I was wondering how do you setup development environment with this project?
Flashing again and again with small changes seems very difficult. How did you develop this library?
If I publish a message with empty data to a subscribed channel the device resets. I'm using the example code with SSL switched off.
TCP: data received
Fatal exception (28):
epc1=0x4000df7c, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000
rm match
pm close 7 0 0/134597350
ets Jan 8 2013,rst cause:4, boot mode:(3,7)
Could you please add an #ifdef around each espconn_secure_.. functions in mqtt.c
I'm running out of memory (esphttpd + mqtt + DS18B20 + ntp client)
Currently:
0x00000.bin -> 41KB
0x40000.bin -> 172KB
After I comment out all the espconn_secure_... functions in mqtt.c :
0x00000.bin -> 38KB
0x40000.bin -> 144KB
I didn't have to remove ssl from the LIBS statement in the makefile.
Hi,
I have downloaded this great project.
In file mqtt.c there is a call for to function:
espconn_secure_disconnect()
espconn_secure_sent()
but there is no implementation.
If I'm wrong please direct me to it.
Thanks
Hi,
Great work, loving the project.
I intend to use the MQTT framework for sending a message from a sensor and then sleep the ESP8266 until it is time to send another message.
There is currently no easy way of knowing when to put the ESP8266 to sleep, as the task system makes it difficult to determine when it is safe to sleep.
Can we add an optional callback function to the MQTTPublish command to be called once the message has been safely sent. I could then add the system_deep_sleep(x) as a callback function to put the system to sleep knowing that the message has been dispatched.
HI
Not sure if there is supposed to be a publish queue but if not is there a chance you could fix this please... sometimes I need to be able to send 2 messages, one after another - and I can't as only the last one gets through as if the first is being over-written. Would REALLY appreciate this?
it would be fine if the field sta_pwd in user_config.h can be increased to 64 Bytes, as it is too small for long WPA2 pass phrases.
If it is not possible please give a warning on too long values for the string parameters.
Hi. I found in the readme:
Limited:
Not fully supported retransmit for QoS1 and QoS2
It's this still true?
Can you confirm that this problem also affects lua port of esp_mqtt (nodemcu)?
Because sometimes I get the published callback on the esp8266 but the broker doesn't receive the message... This occurs when i send a lot of messages in short time.
It seems incomming data variable keeps old data, cf.
Send 1st packet with "1234567890"
Then send second packet with "abcd"
The ESP8266 reports :
MQTT: Subscribe successful
TCP: data received
MQTT topic: /test2/topic1234567890, data: 1234567890
TCP: data received
MQTT topic: /test2/topicabcd567890, data: abcd567890
Hi, Tuan
After updating with the last commit that resolved scargill issue with connectivity I've problems in connecting to the mosquitto broker. I guess that is the the same issue as in #35 since I have on my broker:
Feb 5 20:23:49 mosquitto[32712]: New connection from 192.168.1.14.
Feb 5 20:23:49 mosquitto[32712]: Invalid protocol "MQTT" in CONNECT from 192.168.1.14.
And from ESP
TCP: Connect to ip 192.168.1.26:1880
TCP: Reconnect to: 192.168.1.26:1880
MQTT: Connected to broker 192.168.1.26:1880
MQTT: Sending, type: 1, id: 0000
TCP: Sent
TCP: Disconnected callback
MQTT: Disconnected
Free memory
Can you help us with this one, please.
Regards,
Catalin
Stunning. I had it working within minutes.. couple of questions... in the user config it refers to two sets of settings for routers etc... I set both the same as I could not figure out which was which - which of the two should I be setting to hook into my router.. and what's the other one for.
The other question is... I got it working with MOSQUITTO. I have my mobile Android phone sending messages to the unit via MOSQUITTO... and that's fine... it subscribes to xxxx/ota and xxxx/data but also it SEEMS to send a message on power up to xxxx/send - but despite having my phone subscribe to that, the phone is not seeing that message... so is that supposed to be working?
As there is no doc that's as far as I can go - it works very well - but did you implement any more... so 2 questions..
Can you initiate a message send via the serial?
Can you do all of this with passwords installed? and if so how? I'd feel a little better with passwords on - I know very little about the PC Mosquitto implementation - I basically just installed and ran it.
Last question.. Am I right in saying that once I can confirm the SEND is working, this could have one ESP8266 send messages to another??
One last question.. the ID number shown in the code as %8X - where is that coming from???
Hi Tuan,
I have updated to your latest version with the makefile that clears out the configuration fields but I still have the issue with configuration not working correct. When I commented out the whole CFG load from memory I've got the things going. Is there any specific reason to write configuration in binary form since you have it anyway in your program?
See the code bellow:
void ICACHE_FLASH_ATTR CFG_Load()
{
INFO("\r\nload ...\r\n");
/* spi_flash_read((CFG_LOCATION + 3) * SPI_FLASH_SEC_SIZE,
(uint32 *)&saveFlag, sizeof(SAVE_FLAG));
if (saveFlag.flag == 0) {
spi_flash_read((CFG_LOCATION + 0) * SPI_FLASH_SEC_SIZE,
(uint32 *)&sysCfg, sizeof(SYSCFG));
} else {
spi_flash_read((CFG_LOCATION + 1) * SPI_FLASH_SEC_SIZE,
(uint32 *)&sysCfg, sizeof(SYSCFG));
}
if(sysCfg.cfg_holder != CFG_HOLDER){/**/
os_memset(&sysCfg, 0x00, sizeof sysCfg);
sysCfg.cfg_holder = CFG_HOLDER;
os_sprintf(sysCfg.sta_ssid, "%s", STA_SSID);
os_sprintf(sysCfg.sta_pwd, "%s", STA_PASS);
sysCfg.sta_type = STA_TYPE;
os_sprintf(sysCfg.device_id, MQTT_CLIENT_ID, system_get_chip_id());
os_sprintf(sysCfg.mqtt_host, "%s", MQTT_HOST);
sysCfg.mqtt_port = MQTT_PORT;
os_sprintf(sysCfg.mqtt_user, "%s", MQTT_USER);
os_sprintf(sysCfg.mqtt_pass, "%s", MQTT_PASS);
sysCfg.security = DEFAULT_SECURITY; /* default non ssl */
sysCfg.mqtt_keepalive = MQTT_KEEPALIVE;
INFO(" default configurations\r\n");
CFG_Save();
// }
INFO("device_ID:%s\r\n",sysCfg.device_id);
INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host);
}
Best regards,
K.
Just downloaded the latest version - I note that things have been moved around.
In the user_config.file I entered my STA_SSID and STA_PASS for my router - and the name of my MQTT host and the port.
I changed the number for CFG_HOLDER - I assume doing this allows the updates to be stored in FLASH.
I compiled for ALL then FLASH - and this is what I'm getting... I have the REALLY SMALL MESSAGE BROKER - and the port is directed back to my house.
This is working with MQTT-SPY and with your original version of the software as of a week ago.
As you can see It is successfully hooking to my router - and finding the address for my broker - but then just continually reconnecting every second....
DNS: found ip 109.170.132.114
TCP: connecting...
TCP: Reconnect to home.scargill.org:1883
TCP: Connect to domain home.scargill.org:1883
TCP:Reconect to: home.scargill.org:1883
DNS: found ip 109.170.132.114
TCP: connecting...
TCP: Reconnect to home.scargill.org:1883
TCP: Connect to domain home.scargill.org:1883
TCP:Reconect to: home.scargill.org:1883
DNS: found ip 109.170.132.114
TCP: connecting...
TCP: Reconnect to home.scargill.org:1883
Cf:
CC user/mqtt.c
user/mqtt.c: In function 'mqtt_tcpclient_recv':
user/mqtt.c:224:8: error: passing argument 1 of 'client->publishedCb' from incompatible pointer type [-Werror]
client->publishedCb(client);
^
user/mqtt.c:224:8: note: expected 'uint32_t ' but argument is of type 'struct MQTT_Client *'
user/mqtt.c:238:8: error: passing argument 1 of 'client->publishedCb' from incompatible pointer type [-Werror]
client->publishedCb(client);
^
user/mqtt.c:238:8: note: expected 'uint32_t *' but argument is of type 'struct MQTT_Client *'
user/mqtt.c: In function 'mqtt_tcpclient_sent_cb':
user/mqtt.c:298:4: error: passing argument 1 of 'client->publishedCb' from incompatible pointer type [-Werror]
client->publishedCb(client);
^
user/mqtt.c:298:4: note: expected 'uint32_t *' but argument is of type 'struct MQTT_Client *'
cc1.exe: all warnings being treated as errors
C:/Users/Xavier/git/esp_mqtt/Makefile:160: recipe for target 'build/user/mqtt.o' failed
mingw32-make.exe: ** [build/user/mqtt.o] Error 1
13:15:16 Build Finished (took 969ms)
The easiest way of building the toolchain seems to be: https://github.com/pfalcon/esp-open-sdk
But that package does not build esptool, instead it expects us to use epstool.py.
esptool.py can not only flash the esp, but also create the .bin files we need when flashing.
I've made a makefile that uses esptool.py instead of esptool.
Yes, it's the old mqtt makefile :)
The only problem is that esptool.py creates the .bin files in the same directory it finds the elf file in. So instead of moving files around i removed the firmware folder and instead put everything inside build.
I could make a pull request if you like, but I've made some other changes to the makefile as well, so maybe it's best if you just copy&paste whatever you like. If you want to ditch esptool at all, that is..
When publishing a message, the mqttPublished callback is not getting called. Using the latest code with the mqttpublish in the connected callback (fix works, thanks), the INFO("MQTT: Published\r\n"); message is never displayed.
MQTT: Send mqtt connection info, to broker 192.168.1.147:1883
TCP: Sent
TCP: data received
MQTT: Connected to 192.168.1.147:1883
TCP: Sent
TCP: data received
MQTT: Subscribe successful
TCP: Sent
TCP: data received
MQTT: Connected
MQTT: sending publish...
MQTT: Subscribe successful
TCP: Sent
TCP: data received
TCP: Sent
TCP: data received
TCP: data received
MQTT topic: /test/topic, data: Hello World
MQTT: sending publish...
TCP: Sent
MQTT: Send keepalive packet to 192.168.1.147:1883!
TCP: Sent
TCP: data received
Surely we should see an MQTT: Published message after the TCP:Sent message?
Hello,
When I subscribe to two topics, as in the initial example, during the mqttConnectedCb the data is not processed from the second subscription in the mqttDataCb. If I send data later, it does work. However, on boot and reconnect, it is not getting this second message.
Similarly, If I subscribe to a wildcard, I do not get the topics passed to the mqttDataCb during the connected stage. It only gets the first message.
I do not know if something else needs added to a queue to get this to work. The reason it is important to get the data from the 2 subscriptions is to restore the state on bootup or reconnect. In this test, I subscribe to two topics:
sensor/node1/control/led1
sensor/node1/control/led2
Below is the relevant output from this test. Thank you for your work.
MQTT: Starting subscription
MQTT: subscribe, topic"sensor/node1/control/led1" at broker 104.200.29.35:1883
MQTT: subscribe, topic"sensor/node1/control/led2" at broker 104.200.29.35:1883
MQTT: queuing publish, length: 24...
MQTT: Sending..
TCP: Sent
MQTT: Published
TCP: data received
MQTT: Sending..
TCP: Sent
MQTT: Published
TCP: data received
MQTT topic: sensor/node1/control/led1, data: on
LED1 sub
LED1 sub data high
MQTT: Sending..
TCP: Sent
MQTT: Published
TCP: data received
When I purpously disconnect the broker and then bring it back up, the ESP8266 will automatically reconnect to the broker, but the subscriptions are lost and hence will not receive any messages anymore.
Is there a call back where I should re-subscribe when the ESP is automatically re-connecting ?
Thanks.
10.10.2
make SDK_BASE="/Users/crapthings/hw/esp_iot_rtos_sdk" FLAVOR="release" all
CC driver/uart.c
make: xtensa-lx106-elf-gcc: No such file or directory
make: *** [build/driver/uart.o] Error 1
Apologies for the issue (still haven't worked out how to use git properly).
Thanks for the updates to the Makefile and to the README.md. I'd like to suggest a very small update to the README.md which might be more realistic for Linux/Mac users:-
for Mac or Linux:
git clone https://github.com/tuanpmt/esp_mqtt
cd esp_mqtt
#clean
make clean
#make
make SDK_BASE="/opt/Espressif/ESP8266_SDK" FLAVOR="release" all
#flash
make ESPPORT="/dev/ttyUSB0" flash
As you know I'm using mqtt as a library component.
I do this by simply adding path_to_mqtt/mqtt to the MODULES variable. What i can't do is to add path_to_mqtt/user to MODULES since then there will be two user_init() functions in the bin.
This used to work, but since you moved wifi.h, wifi.c, config.h and config.c to path_to_mqtt/user my builds fail.
I suggest you move those files back to path_to_mqtt/mqtt or create another module folder.
I cannot reopen a closed bug, so here goes...
#12 appears to be broken again with the latest version :(
All I've done is insert
MQTT_Publish(&mqttClient, "/test/topic", "Hello World 99", 14, 2, 0);
at the end of the mqttConnectedCb, and the message never gets sent.
ip:192.168.1.47,mask:255.255.255.0,gw:192.168.1.1
TCP: Connect to ip 192.168.1.147:1883
MQTT: Connected to broker 192.168.1.147:1883
MQTT: Send mqtt connection info, to broker 192.168.1.147:1883
TCP: Sent
TCP: data received
MQTT: Connected to 192.168.1.147:1883
MQTT: Connected
MQTT: subscribe, topic"/test/topic" at broker 192.168.1.147:1883
MQTT: subscribe, topic"/test2/topic" at broker 192.168.1.147:1883
TCP: Sent
TCP: data received
MQTT: Subscribe successful
TCP: Sent
TCP: data received
MQTT: Subscribe successful
MQTT: Send keepalive packet to 192.168.1.147:1883!
TCP: Sent
MQTT: Published
TCP: data received
Does this support LWT? If so can you show an example?
If not, can you please add it?
Thank you
Sorry guys for the noob question but maybe someone can help me.
I have a working esp_mqtt setup. I can publish data and subscribe to a topic.
My question is now:
How can I use the received data to turn a led on and off.
The received data gets processed in the void mqttDataCb() function.
The problem: I cant just do
if(data=="on") {
gpio_output_set(BIT0|BIT2, 0, BIT0|BIT2, 0); //Set GPIO2 to HIGH / LED ON
}
What would be the right way?
On my module everything works fine until the keepalive packet is sent. On rare occasions this succeeds but for the most everything stops working. This is what I get (with some extra output, with comments):
MQTT: Send keepalive packet to 192.168.1.100:1883!
MQTT: Sending..
TCP: Reconnect to 192.168.1.100:1883 [error -3] // -3 is ESPCONN_TIMEOUT
MQTT: Recon timeout
TCP: Connect to ip 192.168.1.100:1883
TCP:Reconect to: 192.168.1.100:1883
TCP: Reconnect to 192.168.1.100:1883 [error -11] // -11 is ESPCONN_CONN, not connected
MQTT: Recon timeout
TCP: Connect to ip 192.168.1.100:1883
TCP:Reconect to: 192.168.1.100:1883
TCP: Reconnect to 192.168.1.100:1883 [error -11]
I will dig into it but I am curious if anyone else has seen this? I just did a git pull and I am using the 0.9.4 SDK.
Hello, I am having issues with the latest updates, somehow it keeps telling me wrong password while I am sure it is right.
I did change the SSID and password in the include/user_config file.
Also I don't see the changes I do in user config file really reflecting in build, I change the server IP and make clean then make the project, I flash with new bins and nth happen, just connecting to same IP.
Hi,
Thanks for adding the callback for published data, which brings forward another issue.
The code I'm trying to implement is to send a temperature reading, then sleep for 15 minutes and repeat. The MQTT_Publish command will ignore any messages until the system is in a ready state (connState == MQTT_DATA) to be able to send messages.
Therefore I need to determine when it is safe to send a message before going to sleep. Looking at the code, the last callback appears to be the mqttConnectCb function. I tried adding my code to read the temperature sensor at the end of this callback, but the MQTT_Publish is ignored (I'm presuming the state is incorrect to send the message).
Is there a way / technique within the callback system to know when i can send a message?
Can the messages be queued to be sent?
Would another callback for readyToSend be practical?
My ESP8266-01 won't connect to my AP.
was getting "no 1 found, reconnect after 1s"
Apparently, the "1" is loaded into SSID on CFG_Load(), getting defaults loaded don't seems to work too.
A temp fix is to force the SSID from the header, after the spi reads in CFG_Load.
os_sprintf(sysCfg.sta_ssid, "%s", STA_SSID);
Hi Tuan,
when using your code in bigger projects (I've got one with HTTP) the RAM is getting full and code could not compile.
I would advise to put ICACHE_FLASH_ATTR on most functions in order to save RAM but not sure if it's applicable for the whole code.
Cheers,
K.
Is it possible to set the device in SoftAP mode when running for the first time. This way we can connect to the device and enter the Wifi details. This would be better because then we don't have to hardcode the wifi details to the device
Hi tuan,
I have been trying at least two weeks ago to configure the device with softap+sta mode with your firmware, but always I can't see the ESP in my network list as AP, the code that I use to configure is this below. Have you tried to use the ESP in this mode with mqtt? I call this function before to connect with MQTT....
void configureAP()
{
static char ssid[33];
static char password[33];
static uint8_t macaddr[6];
struct softap_config apConfig;
os_bzero(&apConfig, sizeof(struct softap_config));
wifi_softap_get_config(&apConfig);
wifi_set_opmode(0x3);
switch(wifi_get_opmode())
{
case STATION_MODE:
INFO("Modo de operação: Station");
break;
case SOFTAP_MODE:
INFO("Modo de operação: Access Point Mode");
break;
case STATIONAP_MODE:
INFO("Modo de operação: Access Point Mode + Station");
break;
}
os_memset(apConfig.password, 0, sizeof(apConfig.password));
os_sprintf(password, "%s", WIFI_APPASSWORD);
os_memcpy(apConfig.password, password, os_strlen(password));
os_memset(apConfig.ssid, 0, sizeof(apConfig.ssid));
os_sprintf(ssid, "%s", WIFI_APSSID);
os_memcpy(apConfig.ssid, ssid, os_strlen(ssid));
//apConfig.authmode = AUTH_WEP;
apConfig.authmode = AUTH_WPA_WPA2_PSK;
//apConfig.authmode = AUTH_OPEN;
apConfig.channel = 4;
apConfig.max_connection = 2;
apConfig.ssid_hidden = 0;
wifi_softap_set_config(&apConfig);
wifi_softap_dhcps_start();
switch(wifi_softap_dhcps_status())
{
case DHCP_STOPPED:
INFO("\nDHCP Server parou!\n");
break;
case DHCP_STARTED:
INFO("\nDHCP Server foi iniciado!\n");
break;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.