Skip to content

Commit 8333b6c

Browse files
committedMar 15, 2024
esp32 cellular aws iot examples
1 parent 4bc0aa0 commit 8333b6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5291
-2
lines changed
 

‎.gitignore

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Prerequisites
22
*.d
3+
*.c
4+
!certificates.c
35

46
# Object files
57
*.o
@@ -18,7 +20,6 @@
1820

1921
# Libraries
2022
*.lib
21-
*.a
2223
*.la
2324
*.lo
2425

@@ -50,3 +51,7 @@ modules.order
5051
Module.symvers
5152
Mkfile.old
5253
dkms.conf
54+
55+
.vscode/
56+
build
57+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/**
2+
* \copyright Copyright (c) 2019-2024, Buildstorm Pvt Ltd
3+
*
4+
* \file 01_ThingPubSubModem.ino
5+
* \brief main entry of the application.
6+
*/
7+
8+
#include "app_config.h"
9+
#include "LibSystem.h"
10+
#include "LibAws.h"
11+
12+
extern const char aws_root_ca_pem[];
13+
extern const char certificate_pem_crt[];
14+
extern const char private_pem_key[];
15+
16+
LibSystem SYS;
17+
Aws AWS;
18+
19+
void app_init();
20+
void app_loop();
21+
22+
void setup()
23+
{
24+
Serial.begin(115200);
25+
app_init();
26+
AWS.subscribe((char *)TEST_AWS_TOPIC_SUBSCRIBE, 0);
27+
}
28+
29+
void loop()
30+
{
31+
app_loop();
32+
delay(200);
33+
}
34+
35+
void app_init()
36+
{
37+
38+
systemInitConfig_st sysConfig = {0};
39+
40+
sysConfig.systemEventCallbackHandler = app_eventsCallBackHandler;
41+
sysConfig.pDeviceNamePrefixStr = NULL;
42+
43+
sysConfig.s_mqttClientConfig.maxPubMsgToStore_u8 = 5;
44+
sysConfig.s_mqttClientConfig.maxSubMsgToStore_u8 = 6;
45+
sysConfig.s_mqttClientConfig.maxSubscribeTopics_u8 = 5;
46+
sysConfig.s_mqttClientConfig.pThingNameStr = (char *)AWS_IOT_THING_NAME;
47+
sysConfig.s_mqttClientConfig.pHostNameStr = (char *)AWS_IOT_MQTT_HOST;
48+
sysConfig.s_mqttClientConfig.port_u16 = AWS_IOT_MQTT_PORT;
49+
sysConfig.s_mqttClientConfig.pRootCaStr = (char *)aws_root_ca_pem;
50+
sysConfig.s_mqttClientConfig.pThingCertStr = (char *)certificate_pem_crt;
51+
sysConfig.s_mqttClientConfig.pThingPrivateKeyStr = (char *)private_pem_key;
52+
53+
sysConfig.s_modemConfig.model = QUECTEL_BG96;
54+
sysConfig.s_modemConfig.uartPortNum_u8 = MODEM_UART_NUM;
55+
sysConfig.s_modemConfig.rxPin_u8 = MODEM_RX_UART_PIN;
56+
sysConfig.s_modemConfig.txPin_u8 = MODEM_TX_UART_PIN;
57+
sysConfig.s_modemConfig.resetKeyPin_u8 = MODEM_RESETKEY_GPIO_PIN;
58+
sysConfig.s_modemConfig.pApn = APN;
59+
sysConfig.s_modemConfig.pApnUsrName = USERID;
60+
sysConfig.s_modemConfig.pApnPwd = PASSWORD;
61+
62+
if (SYS.init(&sysConfig))
63+
{
64+
SYS.start();
65+
}
66+
else
67+
{
68+
while (1)
69+
{
70+
printf("\n System Init failed, verify the init config ....");
71+
delay(5000);
72+
}
73+
}
74+
}
75+
76+
void app_loop()
77+
{
78+
79+
static uint32_t nextPubTime = 0;
80+
static uint32_t count_u32 = 100;
81+
82+
if (SYS.getMode() == SYSTEM_MODE_NORMAL)
83+
{
84+
if (AWS.isConnected())
85+
{
86+
mqttMsg_st s_mqttMsg = {0};
87+
if (AWS.read(&s_mqttMsg))
88+
{
89+
printf("\n Received: [%s]:%s", s_mqttMsg.topicStr, s_mqttMsg.payloadStr);
90+
}
91+
if ((millis() > nextPubTime))
92+
{
93+
94+
s_mqttMsg.payloadLen_u16 = sprintf(s_mqttMsg.payloadStr, "{\"count\": %d}", count_u32++);
95+
strcpy(s_mqttMsg.topicStr, TEST_AWS_TOPIC_PUBLISH);
96+
s_mqttMsg.qos_e = QOS0_AT_MOST_ONCE;
97+
AWS.publish(&s_mqttMsg);
98+
nextPubTime = millis() + 5000;
99+
printf("\n %s\n", s_mqttMsg.payloadStr);
100+
}
101+
}
102+
}
103+
}
104+
105+
void app_eventsCallBackHandler(systemEvents_et event_e)
106+
{
107+
switch (event_e)
108+
{
109+
case EVENT_WIFI_CONNECTED:
110+
printf("\nEVENT_WIFI_CONNECTED");
111+
break;
112+
case EVENT_WIFI_DISCONNECTED:
113+
printf("\nEVENT_WIFI_DISCONNECTED");
114+
break;
115+
116+
case EVENT_MQTT_CONNECTED:
117+
printf("\nEVENT_AWS_CONNECTED");
118+
break;
119+
case EVENT_MQTT_DISCONNECTED:
120+
printf("\nEVENT_AWS_DISCONNECTED");
121+
break;
122+
123+
case EVENT_BLE_CONNECTED:
124+
printf("\nEVENT_BLE_CONNECTED");
125+
break;
126+
case EVENT_BLE_AUTHENTICATED:
127+
printf("\nEVENT_BLE_AUTHENTICATED");
128+
break;
129+
case EVENT_BLE_DISCONNECTED:
130+
printf("\nEVENT_BLE_DISCONNECTED");
131+
break;
132+
133+
default:
134+
break;
135+
}
136+
}

0 commit comments

Comments
 (0)
Please sign in to comment.