Skip to content

Commit

Permalink
Updates, additions, bug fixes
Browse files Browse the repository at this point in the history
'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, ...
  • Loading branch information
loboris committed May 10, 2018
1 parent c6aa0c6 commit 5ca4ebb
Show file tree
Hide file tree
Showing 250 changed files with 19,037 additions and 11,880 deletions.
1 change: 1 addition & 0 deletions MicroPython_BUILD/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/mdns/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/ethernet/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/esp_adc_cal/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${IDF_PATH}/components/nghttp/port/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MicroPython_BUILD}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MicroPython_BUILD/build/include}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/MicroPython_BUILD/components/micropython/genhdr}&quot;"/>
Expand Down
2 changes: 2 additions & 0 deletions MicroPython_BUILD/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ build/

patches/

qstrdefs.generated.h
partitions_mpy.csv
/sdkconfig
sdkconfig.old
Expand All @@ -35,3 +36,4 @@ sdkconfig.fw_psram_all

make_firmwares.sh
mncfg_exit.txt
updates.txt
18 changes: 11 additions & 7 deletions MicroPython_BUILD/BUILD.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@

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

# Note:
# Multiple commands can be given
# Multiple options and commands can be given


# #################################################################
Expand All @@ -48,7 +50,7 @@


#=======================
TOOLS_VER=ver20180412.id
TOOLS_VER=ver20180510.id
#=======================

# -----------------------------
Expand All @@ -64,6 +66,8 @@ FORCE_3PART="no"
POSITIONAL_ARGS=()
BUILD_TYPE=""
BUILD_BASE_DIR=${PWD}
BUILD_COMPORT=""
BUILD_BDRATE=""

# ---------------------------------------
# Include functions used in build process
Expand Down
24 changes: 19 additions & 5 deletions MicroPython_BUILD/build_func.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ get_arguments() {
;;
-fs|--fssize)
FS_SIZE="$2"
shift # past argument
shift # past value
;;
-p|--port)
BUILD_COMPORT="$2"
BUILD_COMPORT=" ESPPORT=${BUILD_COMPORT}"

shift # past argument
shift # past value
;;
-b|--bdrate)
BUILD_BDRATE="$2"
BUILD_BDRATE=" ESPBAUD=${BUILD_BDRATE}"

shift # past argument
shift # past value
;;
Expand Down Expand Up @@ -176,7 +190,7 @@ set_partitions() {
fi

echo "# -------------------------------------------------------" > partitions_mpy.csv
echo "# - Partition layout generaded by BUILD.sh script -" >> partitions_mpy.csv
echo "# - Partition layout generated by BUILD.sh script -" >> partitions_mpy.csv
echo "# -------------------------------------------------------" >> partitions_mpy.csv
echo "# Name, Type, SubType, Offset, Size, Flags" >> partitions_mpy.csv
echo "# -------------------------------------------------------" >> partitions_mpy.csv
Expand Down Expand Up @@ -219,7 +233,7 @@ set_partitions() {
fi

echo "# -------------------------------------------------------" > partitions_mpy.csv
echo "# - Partition layout generaded by BUILD.sh script -" >> partitions_mpy.csv
echo "# - Partition layout generated by BUILD.sh script -" >> partitions_mpy.csv
echo "# -------------------------------------------------------" >> partitions_mpy.csv
echo "# Name, Type, SubType, Offset, Size, Flags" >> partitions_mpy.csv
echo "# -------------------------------------------------------" >> partitions_mpy.csv
Expand Down Expand Up @@ -598,21 +612,21 @@ executeCommand() {
echo "========================================="
echo "Flashing MicroPython firmware to ESP32..."
echo "========================================="
make ${J_OPTION} ${arg} 2>/dev/null
make ${J_OPTION} ${arg}${BUILD_COMPORT}${BUILD_BDRATE} 2>/dev/null

# ---------------------------------
elif [ "${arg}" == "erase" ]; then
echo "======================"
echo "Erasing ESP32 Flash..."
echo "======================"
make erase_flash
make erase_flash${BUILD_COMPORT}${BUILD_BDRATE}

# ----------------------------------
elif [ "${arg}" == "monitor" ]; then
echo "============================"
echo "Executing esp-idf monitor..."
echo "============================"
make monitor
make monitor${BUILD_COMPORT}

# ---------------------------------
elif [ "${arg}" == "clean" ]; then
Expand Down
3 changes: 3 additions & 0 deletions MicroPython_BUILD/components/espmqtt/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
# Debug files
*.dSYM/
*.su
build
examples/**/build
examples/**/sdkconfig*
174 changes: 172 additions & 2 deletions MicroPython_BUILD/components/espmqtt/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,175 @@
[![](https://travis-ci.org/tuanpmt/espmqtt.svg?branch=master)](https://travis-ci.org/tuanpmt/espmqtt)
[![](http://hits.dwyl.io/tuanpmt/espmqtt.svg)](http://hits.dwyl.io/tuanpmt/espmqtt)
[![Twitter Follow](https://img.shields.io/twitter/follow/tuanpmt.svg?style=social&label=Follow)](https://twitter.com/tuanpmt)
![GitHub contributors](https://img.shields.io/github/contributors/tuanpmt/espmqtt.svg)

# ESP32 MQTT Library

This is component based on ESP-IDF for ESP32
## Features

- Based on: https://github.com/tuanpmt/esp_mqtt
- Support MQTT over TCP, SSL with mbedtls, MQTT over Websocket, MQTT over Websocket Secure
- Easy to setup with URI
- Multiple instances (Multiple clients in one application)
- Support subscribing, publishing, authentication, will messages, keep alive pings and all 3 QoS levels (it should be a fully functional client).

## How to use

Clone this component to [ESP-IDF](https://github.com/espressif/esp-idf) project (as submodule):
```
git submodule add https://github.com/tuanpmt/espmqtt.git components/espmqtt
```

Or run a sample (make sure you have installed the [toolchain](http://esp-idf.readthedocs.io/en/latest/get-started/index.html#setup-toolchain)):

```
git clone https://github.com/tuanpmt/espmqtt.git
cd espmqtt/examples/mqtt_tcp
make menuconfig
make flash monitor
```

## Documentation
### URI

- Curently support `mqtt`, `mqtts`, `ws`, `wss` schemes
- MQTT over TCP samples:
+ `mqtt://iot.eclipse.org`: MQTT over TCP, default port 1883:
+ `mqtt://iot.eclipse.org:1884` MQTT over TCP, port 1884:
+ `mqtt://username:password@iot.eclipse.org:1884` MQTT over TCP, port 1884, with username and password
- MQTT over SSL samples:
+ `mqtts://iot.eclipse.org`: MQTT over SSL, port 8883
+ `mqtts://iot.eclipse.org:8884`: MQTT over SSL, port 8884
- MQTT over Websocket samples:
+ `ws://iot.eclipse.org:80/ws`
- MQTT over Websocket Secure samples:
+ `wss://iot.eclipse.org:443/ws`
- Minimal configurations:

```c
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtt://iot.eclipse.org",
.event_handle = mqtt_event_handler,
// .user_context = (void *)your_context
};
```

- 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:

```c
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtt://iot.eclipse.org:1234",
.event_handle = mqtt_event_handler,
.port = 4567,
};
//MQTT client will connect to iot.eclipse.org using port 4567
```


### SSL

- 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`
- Check the sample application: `examples/mqtt_ssl`
- Configuration:

```cpp
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtts://iot.eclipse.org:8883",
.event_handle = mqtt_event_handler,
.cert_pem = (const char *)iot_eclipse_org_pem_start,
};
```


### More options for `esp_mqtt_client_config_t`

- `event_handle` for MQTT events
- `host`: MQTT server domain (ipv4 as string)
- `port`: MQTT server port
- `client_id`: default client id is `ESP32_%CHIPID%`
- `username`: MQTT username
- `password`: MQTT password
- `lwt_topic, lwt_msg, lwt_qos, lwt_retain, lwt_msg_len`: are mqtt lwt options, default NULL
- `disable_clean_session`: mqtt clean session, default clean_session is true
- `keepalive`: (value in seconds) mqtt keepalive, default is 120 seconds
- `disable_auto_reconnect`: this mqtt client will reconnect to server (when errors/disconnect). Set `disable_auto_reconnect=true` to disable
- `user_context` pass user context to this option, then can receive that context in `event->user_context`
- `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`).
- `buffer_size` for MQTT send/receive buffer, default is 1024
- `cert_pem` pointer to CERT file for server verify (with SSL), default is NULL, not required to verify the server
- `transport`: override URI transport
+ `MQTT_TRANSPORT_OVER_TCP`: MQTT over TCP, using scheme: `mqtt`
+ `MQTT_TRANSPORT_OVER_SSL`: MQTT over SSL, using scheme: `mqtts`
+ `MQTT_TRANSPORT_OVER_WS`: MQTT over Websocket, using scheme: `ws`
+ `MQTT_TRANSPORT_OVER_WSS`: MQTT over Websocket Secure, using scheme: `wss`

### Change settings in `menuconfig`

```
make menuconfig
-> Component config -> ESPMQTT Configuration
```

## Example

Check `examples/mqtt_tcp` and `examples/mqtt_ssl` project. In Short:

```cpp

static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
{
esp_mqtt_client_handle_t client = event->client;
int msg_id;
// your_context_t *context = event->context;
switch (event->event_id) {
case MQTT_EVENT_CONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);

msg_id = esp_mqtt_client_subscribe(client, "/topic/qos1", 1);
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);

msg_id = esp_mqtt_client_unsubscribe(client, "/topic/qos1");
ESP_LOGI(TAG, "sent unsubscribe successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGI(TAG, "MQTT_EVENT_DISCONNECTED");
break;

case MQTT_EVENT_SUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
msg_id = esp_mqtt_client_publish(client, "/topic/qos0", "data", 0, 0, 0);
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGI(TAG, "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI(TAG, "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGI(TAG, "MQTT_EVENT_DATA");
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);
break;
case MQTT_EVENT_ERROR:
ESP_LOGI(TAG, "MQTT_EVENT_ERROR");
break;
}
return ESP_OK;
}
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = "mqtt://iot.eclipse.org",
.event_handle = mqtt_event_handler,
// .user_context = (void *)your_context
};

esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
esp_mqtt_client_start(client);
```
## License
Full documentation and sample project: https://github.com/tuanpmt/esp32-mqtt
[@tuanpmt](https://twitter.com/tuanpmt)
Apache License
7 changes: 2 additions & 5 deletions MicroPython_BUILD/components/espmqtt/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
# please read the SDK documents if you need to do this.
#
COMPONENT_ADD_INCLUDEDIRS := include
#COMPONENT_PRIV_INCLUDEDIRS :=

#EXTRA_CFLAGS := -DICACHE_RODATA_ATTR
CFLAGS += -Wno-error=implicit-function-declaration -Wno-error=format= -DHAVE_CONFIG_H
COMPONENT_SRCDIRS := . lib
COMPONENT_PRIV_INCLUDEDIRS := lib/include
Loading

0 comments on commit 5ca4ebb

Please sign in to comment.