Skip to content

Commit 932bb04

Browse files
committed
Merge remote-tracking branch 'origin/develop' into bug/low_power_leds
2 parents ee0e494 + 9705174 commit 932bb04

File tree

12 files changed

+137
-129
lines changed

12 files changed

+137
-129
lines changed

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
<p align="center">
55
<img width="50%" style={{paddingTop: "10px", paddingBottom: "10px"}} src="./readme_images/mini-board-2.png" />
66
</p>
7+
8+
## Installation Instructions
9+
10+
Open the [releases tab](https://github.com/microchip-pic-avr-solutions/avr-iot-cellular-arduino-library/releases/latest) and download the latest version as a zip folder. It is found under the Assets tab. The file to download has the following naming scheme *avr-iot-cellular-a.b.c-\*.zip*.
11+
12+
**It is important to download the library from the releases and not clone it as a git repository.** This has to do with a library dependency to *cryptoauthlib*, which is bundled as a pre-compiled static library with the .zip file from the [releases tab](https://github.com/microchip-pic-avr-solutions/avr-iot-cellular-arduino-library/releases/latest). This is not the case if directly cloning the repository. If it is necessary to clone the repository (for the development of the library itself), see [Build Instructions](#build-instructions) further down on the page.
13+
14+
## Board Description
15+
716
The AVR-IoT Cellular Mini is a development board from Microchip to develop cellular IoT applications.
817

918
📓 Full Arduino support through a library built on top of the open-source [DxCore](https://github.com/SpenceKonde/DxCore)
@@ -20,10 +29,9 @@ The AVR-IoT Cellular Mini is a development board from Microchip to develop cellu
2029

2130
🤝 Built & Designed to be Familiar to Makers, featuring a [Adafruit Feather](https://learn.adafruit.com/adafruit-feather) form-factor and a [Qwiic](https://www.sparkfun.com/qwiic) / [Stemma](https://learn.adafruit.com/introducing-adafruit-stemma-qt) Connector
2231

23-
24-
2532
## 👉 *Documentation: https://iot.microchip.com/docs/* 👈
2633

34+
2735
## Examples
2836

2937
A set of examples can be in [src/examples](./src/examples/), and in the respective user guides on the [documentation website](https://iot.microchip.com/docs/arduino/userguide/architecture).
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,125 @@
1-
/**
2-
* This example uses polling for the LTE module and the MQTT module when
3-
* checking for new messages.
4-
*/
5-
6-
#include <Arduino.h>
7-
8-
#include <ecc608.h>
9-
#include <led_ctrl.h>
10-
#include <log.h>
11-
#include <lte.h>
12-
#include <mqtt_client.h>
13-
14-
#define MQTT_SUB_TOPIC "mchp_topic"
15-
#define MQTT_PUB_TOPIC "mchp_topic"
16-
17-
#define MQTT_THING_NAME "someuniquemchp"
18-
#define MQTT_BROKER "test.mosquitto.org"
19-
#define MQTT_PORT 1883
20-
#define MQTT_USE_TLS false
21-
#define MQTT_USE_ECC false
22-
#define MQTT_KEEPALIVE 60
23-
24-
volatile bool lteConnected = false;
25-
volatile bool mqttConnected = false;
26-
27-
void mqttDisconnectHandler() { mqttConnected = false; }
28-
29-
void lteDisconnectHandler() { lteConnected = false; }
30-
31-
void connectMqtt() {
32-
MqttClient.onConnectionStatusChange(NULL, mqttDisconnectHandler);
33-
34-
mqttConnected = MqttClient.begin(MQTT_THING_NAME,
35-
MQTT_BROKER,
36-
MQTT_PORT,
37-
MQTT_USE_TLS,
38-
MQTT_KEEPALIVE,
39-
MQTT_USE_ECC);
40-
41-
if (mqttConnected) {
42-
Log.info("Connecting to broker...");
43-
while (!MqttClient.isConnected()) {
44-
Log.info("Connecting...");
45-
delay(500);
46-
47-
// If we're not connected to the network, give up
48-
if (!lteConnected) {
49-
return;
50-
}
51-
}
52-
53-
Log.info("Connected to broker!");
54-
55-
MqttClient.subscribe(MQTT_SUB_TOPIC);
56-
} else {
57-
Log.error("Failed to connect to broker");
58-
}
59-
}
60-
61-
void connectLTE() {
62-
63-
Lte.onConnectionStatusChange(NULL, lteDisconnectHandler);
64-
65-
// Start LTE modem and wait until we are connected to the operator
66-
Lte.begin();
67-
68-
while (!Lte.isConnected()) {
69-
Log.info("Not connected to operator yet...");
70-
delay(5000);
71-
}
72-
73-
Log.info("Connected to operator!");
74-
lteConnected = true;
75-
}
76-
77-
void setup() {
78-
Log.begin(115200);
79-
LedCtrl.begin();
80-
LedCtrl.startupCycle();
81-
82-
Log.info("Starting initialization of MQTT Polling");
83-
}
84-
85-
static uint32_t counter = 0;
86-
87-
void loop() {
88-
89-
if (mqttConnected) {
90-
91-
String message = MqttClient.readMessage(MQTT_SUB_TOPIC);
92-
93-
// Read message will return an empty string if there were no new
94-
// messages, so anything other than that means that there were a new
95-
// message
96-
if (message != "") {
97-
Log.infof("Got new message: %s\r\n", message.c_str());
98-
}
99-
100-
String message_to_publish = String("Hello world: " + String(counter));
101-
102-
bool publishedSuccessfully =
103-
MqttClient.publish(MQTT_PUB_TOPIC, message_to_publish.c_str());
104-
105-
if (publishedSuccessfully) {
106-
Log.infof("Published message: %s\r\n", message_to_publish.c_str());
107-
counter++;
108-
} else {
109-
Log.error("Failed to publish");
110-
}
111-
} else {
112-
// MQTT is not connected. Need to establish connection
113-
114-
if (!lteConnected) {
115-
// We're NOT connected to the LTE Network. Establish LTE connection
116-
// first
117-
Log.info("LTE is not connected. Establishing...");
118-
connectLTE();
119-
}
120-
121-
connectMqtt();
122-
}
123-
124-
delay(1000);
125-
}
1+
/**
2+
* This example uses polling for the LTE module and the MQTT module when
3+
* checking for new messages.
4+
*/
5+
6+
#include <Arduino.h>
7+
8+
#include <ecc608.h>
9+
#include <led_ctrl.h>
10+
#include <log.h>
11+
#include <lte.h>
12+
#include <mqtt_client.h>
13+
14+
#define MQTT_SUB_TOPIC "mchp_topic"
15+
#define MQTT_PUB_TOPIC "mchp_topic"
16+
17+
#define MQTT_THING_NAME "someuniquemchp"
18+
#define MQTT_BROKER "test.mosquitto.org"
19+
#define MQTT_PORT 1883
20+
#define MQTT_USE_TLS false
21+
#define MQTT_USE_ECC false
22+
#define MQTT_KEEPALIVE 60
23+
24+
volatile bool lteConnected = false;
25+
volatile bool mqttConnected = false;
26+
27+
void mqttDisconnectHandler() { mqttConnected = false; }
28+
29+
void lteDisconnectHandler() { lteConnected = false; }
30+
31+
void connectMqtt() {
32+
MqttClient.onConnectionStatusChange(NULL, mqttDisconnectHandler);
33+
34+
mqttConnected = MqttClient.begin(MQTT_THING_NAME,
35+
MQTT_BROKER,
36+
MQTT_PORT,
37+
MQTT_USE_TLS,
38+
MQTT_KEEPALIVE,
39+
MQTT_USE_ECC);
40+
41+
if (mqttConnected) {
42+
Log.info("Connecting to broker...");
43+
while (!MqttClient.isConnected()) {
44+
Log.info("Connecting...");
45+
delay(500);
46+
47+
// If we're not connected to the network, give up
48+
if (!lteConnected) {
49+
return;
50+
}
51+
}
52+
53+
Log.info("Connected to broker!");
54+
55+
MqttClient.subscribe(MQTT_SUB_TOPIC);
56+
} else {
57+
Log.error("Failed to connect to broker");
58+
}
59+
}
60+
61+
void connectLTE() {
62+
63+
Lte.onConnectionStatusChange(NULL, lteDisconnectHandler);
64+
65+
// Start LTE modem and wait until we are connected to the operator
66+
Lte.begin();
67+
68+
while (!Lte.isConnected()) {
69+
Log.info("Not connected to operator yet...");
70+
delay(5000);
71+
}
72+
73+
Log.info("Connected to operator!");
74+
lteConnected = true;
75+
}
76+
77+
void setup() {
78+
Log.begin(115200);
79+
LedCtrl.begin();
80+
LedCtrl.startupCycle();
81+
82+
Log.info("Starting initialization of MQTT Polling");
83+
}
84+
85+
static uint32_t counter = 0;
86+
87+
void loop() {
88+
89+
if (mqttConnected) {
90+
91+
String message = MqttClient.readMessage(MQTT_SUB_TOPIC);
92+
93+
// Read message will return an empty string if there were no new
94+
// messages, so anything other than that means that there were a new
95+
// message
96+
if (message != "") {
97+
Log.infof("Got new message: %s\r\n", message.c_str());
98+
}
99+
100+
String message_to_publish = String("Hello world: " + String(counter));
101+
102+
bool publishedSuccessfully =
103+
MqttClient.publish(MQTT_PUB_TOPIC, message_to_publish.c_str());
104+
105+
if (publishedSuccessfully) {
106+
Log.infof("Published message: %s\r\n", message_to_publish.c_str());
107+
counter++;
108+
} else {
109+
Log.error("Failed to publish");
110+
}
111+
} else {
112+
// MQTT is not connected. Need to establish connection
113+
114+
if (!lteConnected) {
115+
// We're NOT connected to the LTE Network. Establish LTE connection
116+
// first
117+
Log.info("LTE is not connected. Establishing...");
118+
connectLTE();
119+
}
120+
121+
connectMqtt();
122+
}
123+
124+
delay(1000);
125+
}
File renamed without changes.

scripts/compile_examples.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/bin/bash
22

33
# Test for AVR-IoT Cellular
4-
for d in src/examples/*/ ; do
4+
for d in examples/*/ ; do
55
echo "Compiling $d...";
66
arduino-cli compile -b DxCore:megaavr:avrdb:appspm=no,chip=avr128db64,clock=24internal,bodvoltage=1v9,bodmode=disabled,eesave=enable,resetpin=reset,millis=tcb2,startuptime=8,wiremode=mors2 --libraries=".." "$d";
77
done
88

99
# Test for AVR-IoT Cellular Mini
10-
for d in src/examples/*/ ; do
10+
for d in examples/*/ ; do
1111
echo "Compiling $d...";
1212
arduino-cli compile -b DxCore:megaavr:avrdb:appspm=no,chip=avr128db48,clock=24internal,bodvoltage=1v9,bodmode=disabled,eesave=enable,resetpin=reset,millis=tcb2,startuptime=8,wiremode=mors2 --libraries=".." "$d" --output-dir "builds/mini/$(basename $d)";
1313
done

0 commit comments

Comments
 (0)