13
13
#include < mqtt_client.h>
14
14
#include < veml3328.h>
15
15
16
- #define USE_PSM true
16
+ #define USE_PSM false
17
17
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
39
25
40
26
void setup () {
41
27
Log.begin (115200 );
@@ -44,13 +30,6 @@ void setup() {
44
30
45
31
Log.info (F (" Starting MQTT with low power" ));
46
32
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
-
54
33
// Configure low power depending on whether to use power save mode or just a
55
34
// complete power down.
56
35
#if USE_PSM
@@ -69,7 +48,12 @@ void setup() {
69
48
// Here we also set the keep alive to 3 minutes to match the sleep period
70
49
// for PSM
71
50
#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);
73
57
#endif
74
58
75
59
Mcp9808.begin ();
@@ -83,14 +67,19 @@ void loop() {
83
67
// If we're not using PSM, all connections will be terminated when power
84
68
// down is issued, so we need to re-establish s connection
85
69
#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);
87
76
#endif
88
77
89
78
char message_to_publish[8 ] = {0 };
90
79
sprintf (message_to_publish, " %lu" , counter);
91
80
92
81
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);
94
83
95
84
if (published_successfully) {
96
85
Log.infof (F (" Published message: %s.\r\n " ), message_to_publish);
0 commit comments