Skip to content

Commit e929eef

Browse files
committed
feat(example): Add mqtt client demo
internal: 6f953538
1 parent db463cb commit e929eef

File tree

7 files changed

+630
-0
lines changed

7 files changed

+630
-0
lines changed

examples/mqtt_demo/Makefile

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#############################################################
2+
# Required variables for each makefile
3+
# Discard this section from all parent makefiles
4+
# Expected variables (with automatic defaults):
5+
# CSRCS (all "C" files in the dir)
6+
# SUBDIRS (all subdirs with a Makefile)
7+
# GEN_LIBS - list of libs to be generated ()
8+
# GEN_IMAGES - list of object file images to be generated ()
9+
# GEN_BINS - list of binaries to be generated ()
10+
# COMPONENTS_xxx - a list of libs/objs in the form
11+
# subdir/lib to be extracted and rolled up into
12+
# a generated lib/image xxx.a ()
13+
#
14+
TARGET = eagle
15+
#FLAVOR = release
16+
FLAVOR = debug
17+
18+
#EXTRA_CCFLAGS += -u
19+
20+
ifndef PDIR # {
21+
GEN_IMAGES= eagle.app.v6.out
22+
GEN_BINS= eagle.app.v6.bin
23+
SPECIAL_MKTARGETS=$(APP_MKTARGETS)
24+
SUBDIRS= \
25+
user
26+
27+
endif # } PDIR
28+
29+
LDDIR = $(SDK_PATH)/ld
30+
31+
CCFLAGS += -Os
32+
33+
TARGET_LDFLAGS = \
34+
-nostdlib \
35+
-Wl,-EL \
36+
--longcalls \
37+
--text-section-literals
38+
39+
ifeq ($(FLAVOR),debug)
40+
TARGET_LDFLAGS += -g -O2
41+
endif
42+
43+
ifeq ($(FLAVOR),release)
44+
TARGET_LDFLAGS += -g -O0
45+
endif
46+
47+
COMPONENTS_eagle.app.v6 = \
48+
user/libuser.a
49+
50+
LINKFLAGS_eagle.app.v6 = \
51+
-L$(SDK_PATH)/lib \
52+
-Wl,--gc-sections \
53+
-nostdlib \
54+
-T$(LD_FILE) \
55+
-Wl,--no-check-sections \
56+
-u call_user_start \
57+
-Wl,-static \
58+
-Wl,--start-group \
59+
-lcirom \
60+
-lgcc \
61+
-lhal \
62+
-lcrypto \
63+
-lfreertos \
64+
-llwip \
65+
-lmain \
66+
-lnet80211 \
67+
-lphy \
68+
-lpp \
69+
-lmbedtls \
70+
-lopenssl \
71+
-lmqtt \
72+
-lwpa \
73+
$(DEP_LIBS_eagle.app.v6)\
74+
-Wl,--end-group
75+
76+
DEPENDS_eagle.app.v6 = \
77+
$(LD_FILE) \
78+
$(LDDIR)/eagle.rom.addr.v6.ld
79+
80+
#############################################################
81+
# Configuration i.e. compile options etc.
82+
# Target specific stuff (defines etc.) goes in here!
83+
# Generally values applying to a tree are captured in the
84+
# makefile at its root level - these are then overridden
85+
# for a subtree within the makefile rooted therein
86+
#
87+
88+
#UNIVERSAL_TARGET_DEFINES = \
89+
90+
# Other potential configuration flags include:
91+
# -DTXRX_TXBUF_DEBUG
92+
# -DTXRX_RXBUF_DEBUG
93+
# -DWLAN_CONFIG_CCX
94+
# -DMQTT_TASK: Define MQTT_TASK to enable MQTT start background
95+
# thread for a client.
96+
CONFIGURATION_DEFINES = -DICACHE_FLASH -DMQTT_TASK
97+
98+
DEFINES += \
99+
$(UNIVERSAL_TARGET_DEFINES) \
100+
$(CONFIGURATION_DEFINES)
101+
102+
DDEFINES += \
103+
$(UNIVERSAL_TARGET_DEFINES) \
104+
$(CONFIGURATION_DEFINES)
105+
106+
107+
#############################################################
108+
# Recursion Magic - Don't touch this!!
109+
#
110+
# Each subtree potentially has an include directory
111+
# corresponding to the common APIs applicable to modules
112+
# rooted at that subtree. Accordingly, the INCLUDE PATH
113+
# of a module can only contain the include directories up
114+
# its parent path, and not its siblings
115+
#
116+
# Required for each makefile to inherit from the parent
117+
#
118+
INCLUDES := $(INCLUDES) -I $(PDIR)include
119+
sinclude $(SDK_PATH)/Makefile
120+
121+
.PHONY: FORCE
122+
FORCE:
123+

examples/mqtt_demo/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Paho MQTT demo
2+
3+
This example shows how to use the Eclipse Paho MQTT as an example of ESP8266 RTOS SDK. In this demo, the following functions can be realized: MQTT publish, subscribe and ping.
4+
5+
1. Config SSID and PASSWORD of the Wi-Fi AP to be connected in user_config.h
6+
7+
2. Config MQTT Broker to be connected in MQTTEcho.c
8+
9+
3. Export SDK_PATH and BIN_PATH, run gen_misc.sh to compile, then download and run the demo
10+
11+
4. MQTT client will connect with the MQTT Broker, subscribe to the topic "ESP8266/sample/sub", and will publish messages
12+
to the topic "ESP8266/sample/pub"

examples/mqtt_demo/gen_misc.sh

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
#!/bin/bash
2+
3+
:<<!
4+
******NOTICE******
5+
MUST set SDK_PATH & BIN_PATH firstly!!!
6+
example:
7+
export SDK_PATH=~/esp_iot_sdk_freertos
8+
export BIN_PATH=~/esp8266_bin
9+
!
10+
11+
export SDK_PATH=$SDK_PATH
12+
export BIN_PATH=$BIN_PATH
13+
14+
echo "gen_misc.sh version 20150911"
15+
echo ""
16+
17+
if [ $SDK_PATH ]; then
18+
echo "SDK_PATH:"
19+
echo "$SDK_PATH"
20+
echo ""
21+
else
22+
echo "ERROR: Please export SDK_PATH in gen_misc.sh firstly, exit!!!"
23+
exit
24+
fi
25+
26+
if [ $BIN_PATH ]; then
27+
echo "BIN_PATH:"
28+
echo "$BIN_PATH"
29+
echo ""
30+
else
31+
echo "ERROR: Please export BIN_PATH in gen_misc.sh firstly, exit!!!"
32+
exit
33+
fi
34+
35+
echo "Please check SDK_PATH & BIN_PATH, enter (Y/y) to continue:"
36+
read input
37+
38+
if [[ $input != Y ]] && [[ $input != y ]]; then
39+
exit
40+
fi
41+
42+
echo ""
43+
44+
echo "Please follow below steps(1-5) to generate specific bin(s):"
45+
echo "STEP 1: use boot_v1.2+ by default"
46+
boot=new
47+
48+
echo "boot mode: $boot"
49+
echo ""
50+
51+
echo "STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin)"
52+
echo "enter (0/1/2, default 0):"
53+
read input
54+
55+
if [ -z "$input" ]; then
56+
if [ $boot != none ]; then
57+
boot=none
58+
echo "ignore boot"
59+
fi
60+
app=0
61+
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
62+
elif [ $input == 1 ]; then
63+
if [ $boot == none ]; then
64+
app=0
65+
echo "choose no boot before"
66+
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
67+
else
68+
app=1
69+
echo "generate bin: user1.bin"
70+
fi
71+
elif [ $input == 2 ]; then
72+
if [ $boot == none ]; then
73+
app=0
74+
echo "choose no boot before"
75+
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
76+
else
77+
app=2
78+
echo "generate bin: user2.bin"
79+
fi
80+
else
81+
if [ $boot != none ]; then
82+
boot=none
83+
echo "ignore boot"
84+
fi
85+
app=0
86+
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
87+
fi
88+
89+
echo ""
90+
91+
echo "STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz)"
92+
echo "enter (0/1/2/3, default 2):"
93+
read input
94+
95+
if [ -z "$input" ]; then
96+
spi_speed=40
97+
elif [ $input == 0 ]; then
98+
spi_speed=20
99+
elif [ $input == 1 ]; then
100+
spi_speed=26.7
101+
elif [ $input == 3 ]; then
102+
spi_speed=80
103+
else
104+
spi_speed=40
105+
fi
106+
107+
echo "spi speed: $spi_speed MHz"
108+
echo ""
109+
110+
echo "STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT)"
111+
echo "enter (0/1/2/3, default 0):"
112+
read input
113+
114+
if [ -z "$input" ]; then
115+
spi_mode=QIO
116+
elif [ $input == 1 ]; then
117+
spi_mode=QOUT
118+
elif [ $input == 2 ]; then
119+
spi_mode=DIO
120+
elif [ $input == 3 ]; then
121+
spi_mode=DOUT
122+
else
123+
spi_mode=QIO
124+
fi
125+
126+
echo "spi mode: $spi_mode"
127+
echo ""
128+
129+
echo "STEP 5: choose spi size and map"
130+
echo " 0= 512KB( 256KB+ 256KB)"
131+
echo " 2=1024KB( 512KB+ 512KB)"
132+
echo " 3=2048KB( 512KB+ 512KB)"
133+
echo " 4=4096KB( 512KB+ 512KB)"
134+
echo " 5=2048KB(1024KB+1024KB)"
135+
echo " 6=4096KB(1024KB+1024KB)"
136+
echo " 7=4096KB(2048KB+2048KB) not support ,just for compatible with nodeMCU board"
137+
echo " 8=8192KB(1024KB+1024KB)"
138+
echo " 9=16384KB(1024KB+1024KB)"
139+
echo "enter (0/2/3/4/5/6/7/8/9, default 0):"
140+
read input
141+
142+
if [ -z "$input" ]; then
143+
spi_size_map=0
144+
echo "spi size: 512KB"
145+
echo "spi ota map: 256KB + 256KB"
146+
elif [ $input == 2 ]; then
147+
spi_size_map=2
148+
echo "spi size: 1024KB"
149+
echo "spi ota map: 512KB + 512KB"
150+
elif [ $input == 3 ]; then
151+
spi_size_map=3
152+
echo "spi size: 2048KB"
153+
echo "spi ota map: 512KB + 512KB"
154+
elif [ $input == 4 ]; then
155+
spi_size_map=4
156+
echo "spi size: 4096KB"
157+
echo "spi ota map: 512KB + 512KB"
158+
elif [ $input == 5 ]; then
159+
spi_size_map=5
160+
echo "spi size: 2048KB"
161+
echo "spi ota map: 1024KB + 1024KB"
162+
elif [ $input == 6 ]; then
163+
spi_size_map=6
164+
echo "spi size: 4096KB"
165+
echo "spi ota map: 1024KB + 1024KB"
166+
elif [ $input == 7 ]; then
167+
spi_size_map=7
168+
echo"not support ,just for compatible with nodeMCU board"
169+
exit
170+
elif [ $input == 8 ]; then
171+
spi_size_map=8
172+
echo "spi size: 8192KB"
173+
echo "spi ota map: 1024KB + 1024KB"
174+
elif [ $input == 9 ]; then
175+
spi_size_map=9
176+
echo "spi size: 16384KB"
177+
echo "spi ota map: 1024KB + 1024KB"
178+
else
179+
spi_size_map=0
180+
echo "spi size: 512KB"
181+
echo "spi ota map: 256KB + 256KB"
182+
fi
183+
184+
echo ""
185+
186+
echo "start..."
187+
echo ""
188+
189+
make clean
190+
191+
make BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* ESPRESSIF MIT License
3+
*
4+
* Copyright (c) 2017 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5+
*
6+
* Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
7+
* it is free of charge, to any person obtaining a copy of this software and associated
8+
* documentation files (the "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11+
* to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all copies or
14+
* substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
*/
24+
25+
#ifndef __USER_CONFIG_H__
26+
#define __USER_CONFIG_H__
27+
28+
#define SSID "TEST001"
29+
#define PASSWORD "1234567890"
30+
31+
#endif
32+

0 commit comments

Comments
 (0)