Skip to content

Commit b41c1cb

Browse files
committed
Use new REGISTER_PORT pattern and moved code back from atomvm_lib
1 parent 1933bf4 commit b41c1cb

20 files changed

+221
-327
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1+
.vscode/*
12
_build/**
23
doc/**
3-
.vscode/*
4-
examples/mqtt_example/rebar.lock
5-
examples/mqtt_example/_build/**
6-
examples/mqtt_example/_checkouts/**
74
rebar.lock

Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
menu "ATOMVM_MQTT_CLIENT Configuration"
2+
3+
config AVM_MQTT_CLIENT_ENABLE
4+
bool "Enable AtomVM MQTT_CLIENT driver"
5+
default y
6+
help
7+
Use this parameter to enable or disable the AtomVM MQTT_CLIENT driver.
8+
9+
endmenu

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
# AtomVM MQTT Port
22

3-
> **NOTICE** The contents of this repository are being moved to the [`atomvm_lib`](https://github.com/fadushin/atomvm_lib) repository. This repo will remain available for some time, until the contents of this repo will be deleted. Eventually, the repository itself will be remove. Please migrate to the [`atomvm_lib`](https://github.com/fadushin/atomvm_lib) repository ASAP. Please note that some interfaces may have changed slightly as part of the transition.
4-
5-
63
This AtomVM Port and Erlang library can be used to connect to MQTT brokers on the ESP32 SoC for any Erlang/Elixir programs targeted for AtomVM on the ESP32 platform.
74

85
This Port is included as an add-on to the AtomVM base image. In order to use this Port in your AtomVM program, you must be able to build the AtomVM virtual machine, which in turn requires installation of the Espressif IDF SDK and tool chain.
96

107
For more information about the MQTT interface on the ESP32, see the [IDF SDK Documentation](https://docs.espressif.com/projects/esp-idf/en/v3.3.4/api-reference/protocolss/mqtt.html)
118

12-
Documentation for this Nif can be found in the following sections:
9+
Documentation for this component can be found in the following sections:
1310

14-
* [Build Instructions](markdown/build.md)
15-
* [Programmer's Guide](markdown/guide.md)
16-
* [Example Program](examples/mqtt_example/README.md)
11+
* [Programmer's Guide](markdown/mqtt_client.md)
12+
* [Example Program](examples/mqtt_client_example/README.md)

component.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
COMPONENT_ADD_INCLUDEDIRS := ports/include
1+
COMPONENT_ADD_INCLUDEDIRS := ports/include ../../main
2+
COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive
23
COMPONENT_SRCDIRS := ports
34
CXXFLAGS += -fno-rtti
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
src/config.erl
2+
_build/**
3+
_checkouts/**
4+
rebar.lock
File renamed without changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# AtomVM MQTT Client Example Program
2+
3+
The `mqtt_client_example` program illustrates use of the MQTT API by connecting to a well-known MQTT broker, and sending and receiving a message on a topic every 5 seconds. Results are displayed on the console.
4+
5+
> Note. Building and flashing the `mqtt_client_example` program requires installation of the [`rebar3`](https://www.rebar3.org) Erlang build tool.
6+
7+
Start my copying the `src/config.erl-template` file to `src/config.erl` and edit the `ssid` and `psk` entries to match your environment.
8+
9+
get() ->
10+
#{
11+
sta => [
12+
{ssid, "myssid"},
13+
{psk, "mypassword"}
14+
]
15+
}.
16+
17+
Build the example program and flash to your device:
18+
19+
shell$ rebar3 packbeam -p
20+
shell$ rebar3 esp32_flash -p /dev/ttyUSB0
21+
22+
> Note. This build step makes use of the [`atomvm_rebar3_plugin`](https://github.com/atomvm/atomvm_rebar3_plugin). See the `README.md` for information about parameters for setting the serial port and baud rate for your platform.
23+
24+
Attach to the console using `minicom` or equivalent:
25+
26+
shell$ minicom -D /dev/ttyUBS0
27+
...
28+
I (1789) NETWORK: SYSTEM_EVENT_STA_CONNECTED received.
29+
I (2899) event: sta ip: 192.168.211.53, mask: 255.255.255.0, gw: 192.168.211.1
30+
I (2899) NETWORK: SYSTEM_EVENT_STA_GOT_IP: 192.168.211.53
31+
Acquired IP address: {192,168,211,53} Netmask: {255,255,255,0} Gateway: {192,168,211,1}
32+
I (2939) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
33+
I (2939) atomvm_mqtt: MQTT_EVENT_BEFORE_CONNECT msg_id: 0
34+
MQTT started.
35+
Connected to "mqtt://mqtt.eclipseprojects.io"; subscribing to <<"atomvm/qos0">>...
36+
Subscribed to <<"atomvm/qos0">>.
37+
Publishing data on topic <<"atomvm/qos0">>
38+
Received data on topic <<"atomvm/qos0">>: echo
39+
Publishing data on topic <<"atomvm/qos0">>
40+
Received data on topic <<"atomvm/qos0">>: echo
41+
Publishing data on topic <<"atomvm/qos0">>
42+
Received data on topic <<"atomvm/qos0">>: echo
43+
Publishing data on topic <<"atomvm/qos0">>
44+
Received data on topic <<"atomvm/qos0">>: echo
45+
...
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{erl_opts, [debug_info]}.
2+
{deps, [
3+
{mqtt_client, {git, "https://github.com/atomvm/atomvm_mqtt_client.git", {branch, "master"}}}
4+
]}.
5+
{plugins, [atomvm_rebar3_plugin]}.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2022 Fred Dushin <[email protected]>
5+
%
6+
% Licensed under the Apache License, Version 2.0 (the "License");
7+
% you may not use this file except in compliance with the License.
8+
% You may obtain a copy of the License at
9+
%
10+
% http://www.apache.org/licenses/LICENSE-2.0
11+
%
12+
% Unless required by applicable law or agreed to in writing, software
13+
% distributed under the License is distributed on an "AS IS" BASIS,
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
% See the License for the specific language governing permissions and
16+
% limitations under the License.
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
-module(config).
21+
22+
-export([get/0]).
23+
24+
%% Copy this file to config.erl and edit to your satisfaction
25+
26+
get() ->
27+
#{
28+
sta => [
29+
{ssid, "myssid"},
30+
{psk, "mypassword"}
31+
]
32+
}.

examples/mqtt_example/src/mqtt_example.app.src renamed to examples/mqtt_client_example/src/mqtt_client_example.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{application, mqtt_example, [
1+
{application, mqtt_client_example, [
22
{description, "An OTP library"},
33
{vsn, "0.1.0"},
44
{registered, []},

0 commit comments

Comments
 (0)