Skip to content

Commit 5ca4ebb

Browse files
committed
Updates, additions, bug fixes
'esp-idf' updated date: 2018-05-08 version: v3.1-dev-961-ga2556229 hash: a2556229aa6f55b16b171e3325ee9ab1943e8552 Added support for runtime detection of SPIRAM firmwares built with SPIRAM support can now run on boards without SPIRAM Added 'GPS' module collecting gps data from separate FreeRTOS task is supported Added built-in finction 'float_precision' precision of floats can be now set at run time Added new method of initializing the 'array' objects size of the array object can be specified, uses much less heap space Updated 'mqtt' module uses new espmqtt library, new features and some bug fixes mqtt over websockets is now supported Updated 'sys' module added function 'espidf_info()', returns information about used esp-idf Updated 'gc' module added function 'collectif()', conditional collect Updated 'upip' module 'pypy' URL updated Updated 'utimeq' module fixed bugs in getting/setting time values Updated 'display' module added 'text_x()' and 'text_y()' Fixed bug when 'mp_hal_ticks_base' was not updated afer soft resets Updated 'network' module ap_if.status('clients') now returns client's mac address and IP address Updated 'uart' module changes needed for 'gps' module, more reliable Updated 'sockets' module from latest official MicroPython Updated 'rtc' module fixed bug in setting time zone in 'ntp_sync()' function Using or not UNICODE can now be configured from 'menuconfig' Updated 'BUILD.sh' added options to select the comm port and/or baud rate Many bug fixes, stability improvements, ...
1 parent c6aa0c6 commit 5ca4ebb

File tree

250 files changed

+19037
-11880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+19037
-11880
lines changed

MicroPython_BUILD/.cproject

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/mdns/include&quot;"/>
5151
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/ethernet/include&quot;"/>
5252
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/esp_adc_cal/include&quot;"/>
53+
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/nghttp/port/include&quot;"/>
5354
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MicroPython_BUILD}&quot;"/>
5455
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MicroPython_BUILD/build/include}&quot;"/>
5556
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MicroPython_BUILD/components/micropython/genhdr}&quot;"/>

MicroPython_BUILD/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ build/
2222

2323
patches/
2424

25+
qstrdefs.generated.h
2526
partitions_mpy.csv
2627
/sdkconfig
2728
sdkconfig.old
@@ -35,3 +36,4 @@ sdkconfig.fw_psram_all
3536

3637
make_firmwares.sh
3738
mncfg_exit.txt
39+
updates.txt

MicroPython_BUILD/BUILD.sh

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@
2929

3030
# Options:
3131
# -jN - make with multicore option, N should be the number of cores used
32-
# -v | --verbose - enable verbose output, default: quiet output
33-
# -f8 | --flashsize8 - declare the Flash size of 8 MB
34-
# -f16 | --flashsize16 - declare the Flash size of 16 MB
35-
# -fs <FS_size> | --fssize=<FS_size> - declare the size of Flash file system in KB
32+
# -v | --verbose - enable verbose output, default: quiet output
33+
# -f8 | --flashsize8 - declare the Flash size of 8 MB
34+
# -f16 | --flashsize16 - declare the Flash size of 16 MB
35+
# -fs <FS_size> | --fssize=<FS_size> - declare the size of Flash file system in KB
3636
# default: fit the Flash size
37-
# -a <app_size> | --appsize=<app_size> - declare the size of application partition in KB
37+
# -a <app_size> | --appsize=<app_size> - declare the size of application partition in KB
3838
# default: auto detect needed size
3939
# the actual size will be 128 KB smaller then the declared size
40+
# -p <comm_port> | --port=<comm_port> - overwritte configured comm port, use the specified instead
41+
# -b <bdrate> | --bdrate=<bdrate> - overwritte configured baud rate, use the specified instead
4042

4143
# Note:
42-
# Multiple commands can be given
44+
# Multiple options and commands can be given
4345

4446

4547
# #################################################################
@@ -48,7 +50,7 @@
4850

4951

5052
#=======================
51-
TOOLS_VER=ver20180412.id
53+
TOOLS_VER=ver20180510.id
5254
#=======================
5355

5456
# -----------------------------
@@ -64,6 +66,8 @@ FORCE_3PART="no"
6466
POSITIONAL_ARGS=()
6567
BUILD_TYPE=""
6668
BUILD_BASE_DIR=${PWD}
69+
BUILD_COMPORT=""
70+
BUILD_BDRATE=""
6771

6872
# ---------------------------------------
6973
# Include functions used in build process

MicroPython_BUILD/build_func.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ get_arguments() {
3030
;;
3131
-fs|--fssize)
3232
FS_SIZE="$2"
33+
shift # past argument
34+
shift # past value
35+
;;
36+
-p|--port)
37+
BUILD_COMPORT="$2"
38+
BUILD_COMPORT=" ESPPORT=${BUILD_COMPORT}"
39+
40+
shift # past argument
41+
shift # past value
42+
;;
43+
-b|--bdrate)
44+
BUILD_BDRATE="$2"
45+
BUILD_BDRATE=" ESPBAUD=${BUILD_BDRATE}"
46+
3347
shift # past argument
3448
shift # past value
3549
;;
@@ -176,7 +190,7 @@ set_partitions() {
176190
fi
177191

178192
echo "# -------------------------------------------------------" > partitions_mpy.csv
179-
echo "# - Partition layout generaded by BUILD.sh script -" >> partitions_mpy.csv
193+
echo "# - Partition layout generated by BUILD.sh script -" >> partitions_mpy.csv
180194
echo "# -------------------------------------------------------" >> partitions_mpy.csv
181195
echo "# Name, Type, SubType, Offset, Size, Flags" >> partitions_mpy.csv
182196
echo "# -------------------------------------------------------" >> partitions_mpy.csv
@@ -219,7 +233,7 @@ set_partitions() {
219233
fi
220234

221235
echo "# -------------------------------------------------------" > partitions_mpy.csv
222-
echo "# - Partition layout generaded by BUILD.sh script -" >> partitions_mpy.csv
236+
echo "# - Partition layout generated by BUILD.sh script -" >> partitions_mpy.csv
223237
echo "# -------------------------------------------------------" >> partitions_mpy.csv
224238
echo "# Name, Type, SubType, Offset, Size, Flags" >> partitions_mpy.csv
225239
echo "# -------------------------------------------------------" >> partitions_mpy.csv
@@ -598,21 +612,21 @@ executeCommand() {
598612
echo "========================================="
599613
echo "Flashing MicroPython firmware to ESP32..."
600614
echo "========================================="
601-
make ${J_OPTION} ${arg} 2>/dev/null
615+
make ${J_OPTION} ${arg}${BUILD_COMPORT}${BUILD_BDRATE} 2>/dev/null
602616

603617
# ---------------------------------
604618
elif [ "${arg}" == "erase" ]; then
605619
echo "======================"
606620
echo "Erasing ESP32 Flash..."
607621
echo "======================"
608-
make erase_flash
622+
make erase_flash${BUILD_COMPORT}${BUILD_BDRATE}
609623

610624
# ----------------------------------
611625
elif [ "${arg}" == "monitor" ]; then
612626
echo "============================"
613627
echo "Executing esp-idf monitor..."
614628
echo "============================"
615-
make monitor
629+
make monitor${BUILD_COMPORT}
616630

617631
# ---------------------------------
618632
elif [ "${arg}" == "clean" ]; then

MicroPython_BUILD/components/espmqtt/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@
3131
# Debug files
3232
*.dSYM/
3333
*.su
34+
build
35+
examples/**/build
36+
examples/**/sdkconfig*
Lines changed: 172 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,175 @@
1+
[![](https://travis-ci.org/tuanpmt/espmqtt.svg?branch=master)](https://travis-ci.org/tuanpmt/espmqtt)
2+
[![](http://hits.dwyl.io/tuanpmt/espmqtt.svg)](http://hits.dwyl.io/tuanpmt/espmqtt)
3+
[![Twitter Follow](https://img.shields.io/twitter/follow/tuanpmt.svg?style=social&label=Follow)](https://twitter.com/tuanpmt)
4+
![GitHub contributors](https://img.shields.io/github/contributors/tuanpmt/espmqtt.svg)
5+
16
# ESP32 MQTT Library
27

3-
This is component based on ESP-IDF for ESP32
8+
## Features
9+
10+
- Based on: https://github.com/tuanpmt/esp_mqtt
11+
- Support MQTT over TCP, SSL with mbedtls, MQTT over Websocket, MQTT over Websocket Secure
12+
- Easy to setup with URI
13+
- Multiple instances (Multiple clients in one application)
14+
- Support subscribing, publishing, authentication, will messages, keep alive pings and all 3 QoS levels (it should be a fully functional client).
15+
16+
## How to use
17+
18+
Clone this component to [ESP-IDF](https://github.com/espressif/esp-idf) project (as submodule):
19+
```
20+
git submodule add https://github.com/tuanpmt/espmqtt.git components/espmqtt
21+
```
22+
23+
Or run a sample (make sure you have installed the [toolchain](http://esp-idf.readthedocs.io/en/latest/get-started/index.html#setup-toolchain)):
24+
25+
```
26+
git clone https://github.com/tuanpmt/espmqtt.git
27+
cd espmqtt/examples/mqtt_tcp
28+
make menuconfig
29+
make flash monitor
30+
```
31+
32+
## Documentation
33+
### URI
34+
35+
- Curently support `mqtt`, `mqtts`, `ws`, `wss` schemes
36+
- MQTT over TCP samples:
37+
+ `mqtt://iot.eclipse.org`: MQTT over TCP, default port 1883:
38+
+ `mqtt://iot.eclipse.org:1884` MQTT over TCP, port 1884:
39+
+ `mqtt://username:password@iot.eclipse.org:1884` MQTT over TCP, port 1884, with username and password
40+
- MQTT over SSL samples:
41+
+ `mqtts://iot.eclipse.org`: MQTT over SSL, port 8883
42+
+ `mqtts://iot.eclipse.org:8884`: MQTT over SSL, port 8884
43+
- MQTT over Websocket samples:
44+
+ `ws://iot.eclipse.org:80/ws`
45+
- MQTT over Websocket Secure samples:
46+
+ `wss://iot.eclipse.org:443/ws`
47+
- Minimal configurations:
48+
49+
```c
50+
const esp_mqtt_client_config_t mqtt_cfg = {
51+
.uri = "mqtt://iot.eclipse.org",
52+
.event_handle = mqtt_event_handler,
53+
// .user_context = (void *)your_context
54+
};
55+
```
56+
57+
- If there are any options related to the URI in `esp_mqtt_client_config_t`, the option defined by the URI will be overridden. Sample:
58+
59+
```c
60+
const esp_mqtt_client_config_t mqtt_cfg = {
61+
.uri = "mqtt://iot.eclipse.org:1234",
62+
.event_handle = mqtt_event_handler,
63+
.port = 4567,
64+
};
65+
//MQTT client will connect to iot.eclipse.org using port 4567
66+
```
67+
68+
69+
### SSL
70+
71+
- Get Certification from server, example: `iot.eclipse.org` `openssl s_client -showcerts -connect iot.eclipse.org:8883 </dev/null 2>/dev/null|openssl x509 -outform PEM >iot_eclipse_org.pem`
72+
- Check the sample application: `examples/mqtt_ssl`
73+
- Configuration:
74+
75+
```cpp
76+
const esp_mqtt_client_config_t mqtt_cfg = {
77+
.uri = "mqtts://iot.eclipse.org:8883",
78+
.event_handle = mqtt_event_handler,
79+
.cert_pem = (const char *)iot_eclipse_org_pem_start,
80+
};
81+
```
82+
83+
84+
### More options for `esp_mqtt_client_config_t`
85+
86+
- `event_handle` for MQTT events
87+
- `host`: MQTT server domain (ipv4 as string)
88+
- `port`: MQTT server port
89+
- `client_id`: default client id is `ESP32_%CHIPID%`
90+
- `username`: MQTT username
91+
- `password`: MQTT password
92+
- `lwt_topic, lwt_msg, lwt_qos, lwt_retain, lwt_msg_len`: are mqtt lwt options, default NULL
93+
- `disable_clean_session`: mqtt clean session, default clean_session is true
94+
- `keepalive`: (value in seconds) mqtt keepalive, default is 120 seconds
95+
- `disable_auto_reconnect`: this mqtt client will reconnect to server (when errors/disconnect). Set `disable_auto_reconnect=true` to disable
96+
- `user_context` pass user context to this option, then can receive that context in `event->user_context`
97+
- `task_prio, task_stack` for MQTT task, default priority is 5, and task_stack = 6144 bytes (or default task stack can be set via `make menucofig`).
98+
- `buffer_size` for MQTT send/receive buffer, default is 1024
99+
- `cert_pem` pointer to CERT file for server verify (with SSL), default is NULL, not required to verify the server
100+
- `transport`: override URI transport
101+
+ `MQTT_TRANSPORT_OVER_TCP`: MQTT over TCP, using scheme: `mqtt`
102+
+ `MQTT_TRANSPORT_OVER_SSL`: MQTT over SSL, using scheme: `mqtts`
103+
+ `MQTT_TRANSPORT_OVER_WS`: MQTT over Websocket, using scheme: `ws`
104+
+ `MQTT_TRANSPORT_OVER_WSS`: MQTT over Websocket Secure, using scheme: `wss`
105+
106+
### Change settings in `menuconfig`
107+
108+
```
109+
make menuconfig
110+
-> Component config -> ESPMQTT Configuration
111+
```
112+
113+
## Example
114+
115+
Check `examples/mqtt_tcp` and `examples/mqtt_ssl` project. In Short:
116+
117+
```cpp
118+
119+
static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
120+
{
121+
esp_mqtt_client_handle_t client = event->client;
122+
int msg_id;
123+
// your_context_t *context = event->context;
124+
switch (event->event_id) {
125+
case MQTT_EVENT_CONNECTED:
126+
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
127+
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
128+
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
129+
130+
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1);
131+
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
132+
133+
msg_id = esp_mqtt_client_unsubscribe(client, "/topic/qos1");
134+
ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id);
135+
break;
136+
case MQTT_EVENT_DISCONNECTED:
137+
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
138+
break;
139+
140+
case MQTT_EVENT_SUBSCRIBED:
141+
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
142+
msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
143+
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
144+
break;
145+
case MQTT_EVENT_UNSUBSCRIBED:
146+
ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
147+
break;
148+
case MQTT_EVENT_PUBLISHED:
149+
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
150+
break;
151+
case MQTT_EVENT_DATA:
152+
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
153+
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
154+
printf("DATA=%.*s\r\n", event->data_len, event->data);
155+
break;
156+
case MQTT_EVENT_ERROR:
157+
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
158+
break;
159+
}
160+
return ESP_OK;
161+
}
162+
const esp_mqtt_client_config_t mqtt_cfg = {
163+
.uri = "mqtt://iot.eclipse.org",
164+
.event_handle = mqtt_event_handler,
165+
// .user_context = (void *)your_context
166+
};
167+
168+
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
169+
esp_mqtt_client_start(client);
170+
```
171+
172+
## License
4173
5-
Full documentation and sample project: https://github.com/tuanpmt/esp32-mqtt
174+
[@tuanpmt](https://twitter.com/tuanpmt)
175+
Apache License

MicroPython_BUILD/components/espmqtt/component.mk

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
77
# please read the SDK documents if you need to do this.
88
#
9-
COMPONENT_ADD_INCLUDEDIRS := include
10-
#COMPONENT_PRIV_INCLUDEDIRS :=
11-
12-
#EXTRA_CFLAGS := -DICACHE_RODATA_ATTR
13-
CFLAGS += -Wno-error=implicit-function-declaration -Wno-error=format= -DHAVE_CONFIG_H
9+
COMPONENT_SRCDIRS := . lib
10+
COMPONENT_PRIV_INCLUDEDIRS := lib/include

0 commit comments

Comments
 (0)