Skip to content

Commit 1a494e7

Browse files
committed
MCU8MASS-2582 Make low power example use test.mosquitto.org instead of AWS
1 parent 7d2a6cb commit 1a494e7

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

examples/mqtt_low_power/mqtt_low_power.ino

+21-32
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,15 @@
1313
#include <mqtt_client.h>
1414
#include <veml3328.h>
1515

16-
#define USE_PSM true
16+
#define USE_PSM false
1717

18-
static char mqtt_pub_topic[128];
19-
20-
bool initMQTTTopics() {
21-
ECC608.begin();
22-
23-
// Find the thing ID and set the publish and subscription topics
24-
uint8_t thingName[128];
25-
size_t thingNameLen = sizeof(thingName);
26-
27-
// -- Get the thingname
28-
ATCA_STATUS status =
29-
ECC608.readProvisionItem(AWS_THINGNAME, thingName, &thingNameLen);
30-
if (status != ATCA_SUCCESS) {
31-
Log.error(F("Could not retrieve thingname from the ECC"));
32-
return false;
33-
}
34-
35-
sprintf_P(mqtt_pub_topic, PSTR("%s/sensors"), thingName);
36-
37-
return true;
38-
}
18+
#define MQTT_THING_NAME "someuniquemchp"
19+
#define MQTT_BROKER "test.mosquitto.org"
20+
#define MQTT_PUB_TOPIC "testtopic"
21+
#define MQTT_PORT 1883
22+
#define MQTT_USE_TLS false
23+
#define MQTT_USE_ECC false
24+
#define MQTT_KEEPALIVE 180
3925

4026
void setup() {
4127
Log.begin(115200);
@@ -44,13 +30,6 @@ void setup() {
4430

4531
Log.info(F("Starting MQTT with low power"));
4632

47-
// First we retrieve the topics we're going to publish to, here using the
48-
// ECC thingname with AWS
49-
if (initMQTTTopics() == false) {
50-
Log.error(F("Unable to initialize the MQTT topics. Stopping..."));
51-
while (1) {}
52-
}
53-
5433
// Configure low power depending on whether to use power save mode or just a
5534
// complete power down.
5635
#if USE_PSM
@@ -69,7 +48,12 @@ void setup() {
6948
// Here we also set the keep alive to 3 minutes to match the sleep period
7049
// for PSM
7150
#if USE_PSM
72-
MqttClient.beginAWS(180);
51+
MqttClient.begin(MQTT_THING_NAME,
52+
MQTT_BROKER,
53+
MQTT_PORT,
54+
MQTT_USE_TLS,
55+
MQTT_KEEPALIVE,
56+
MQTT_USE_ECC);
7357
#endif
7458

7559
Mcp9808.begin();
@@ -83,14 +67,19 @@ void loop() {
8367
// If we're not using PSM, all connections will be terminated when power
8468
// down is issued, so we need to re-establish s connection
8569
#if !USE_PSM
86-
MqttClient.beginAWS();
70+
MqttClient.begin(MQTT_THING_NAME,
71+
MQTT_BROKER,
72+
MQTT_PORT,
73+
MQTT_USE_TLS,
74+
MQTT_KEEPALIVE,
75+
MQTT_USE_ECC);
8776
#endif
8877

8978
char message_to_publish[8] = {0};
9079
sprintf(message_to_publish, "%lu", counter);
9180

9281
bool published_successfully =
93-
MqttClient.publish(mqtt_pub_topic, message_to_publish, AT_LEAST_ONCE);
82+
MqttClient.publish(MQTT_PUB_TOPIC, message_to_publish, AT_LEAST_ONCE);
9483

9584
if (published_successfully) {
9685
Log.infof(F("Published message: %s.\r\n"), message_to_publish);

0 commit comments

Comments
 (0)