Skip to content

Commit 678b3f8

Browse files
committed
provided examples for GSM
1 parent 18d3cbb commit 678b3f8

File tree

5 files changed

+368
-1
lines changed

5 files changed

+368
-1
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
#define TINY_GSM_MODEM_SIM7600
2+
#include <TinyGsmClient.h>
3+
#include <BytebeamArduino.h>
4+
5+
#define LED_PIN 12
6+
#define MODEM_PWRKEY 4
7+
#define MODEM_FLIGHT 25
8+
#define MODEM_TX 27
9+
#define MODEM_RX 26
10+
11+
// set GSM PIN, if any
12+
#define GSM_PIN ""
13+
14+
#define SerialMon Serial
15+
#define SerialAT Serial1
16+
17+
// Your GPRS credentials, if any
18+
const char apn[] = "";
19+
const char gprsUser[] = "";
20+
const char gprsPass[] = "";
21+
22+
const char* fwVersion = "1.0.0";
23+
24+
TinyGsm modem(SerialAT);
25+
26+
// function to setup the modem with predefined credentials
27+
void setupModem() {
28+
// configure your reset, enable pins here if needed
29+
pinMode(LED_PIN, OUTPUT);
30+
pinMode(MODEM_PWRKEY, OUTPUT);
31+
pinMode(MODEM_FLIGHT, OUTPUT);
32+
33+
// set the status led pin low to indicate the start process
34+
digitalWrite(LED_PIN, LOW);
35+
36+
// pull up power pin (IO:4) Modulator power key, need to powered up the modem
37+
// this pin must be held high for more than 1 second according to manual requirements
38+
digitalWrite(MODEM_PWRKEY, LOW);
39+
delay(100);
40+
digitalWrite(MODEM_PWRKEY, HIGH);
41+
delay(1000);
42+
digitalWrite(MODEM_PWRKEY, LOW);
43+
44+
// pull up the power pin (IO:25) Modulator flight mode control, need to enable modulator
45+
// this pin must be set to high
46+
digitalWrite(MODEM_FLIGHT, HIGH);
47+
48+
SerialMon.println("Modem Powered ON");
49+
50+
// start the serial communication b/w esp32 and modem
51+
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
52+
delay(6000);
53+
54+
// Restart takes quite some time
55+
// To skip it, call init() instead of restart()
56+
modem.restart();
57+
// modem.init();
58+
59+
// set the network mode (2 : Automatic)
60+
modem.setNetworkMode(2);
61+
62+
String modemName = modem.getModemName();
63+
SerialMon.printf("Modem Name : ");
64+
SerialMon.println(modemName);
65+
66+
String modemInfo = modem.getModemInfo();
67+
SerialMon.print("Modem Info : ");
68+
SerialMon.println(modemInfo);
69+
70+
// Unlock your SIM card with a PIN if needed
71+
if(GSM_PIN && modem.getSimStatus() != 3) {
72+
modem.simUnlock(GSM_PIN);
73+
}
74+
75+
SimStatus simStatus = modem.getSimStatus();
76+
77+
if(simStatus != SIM_READY) {
78+
SerialMon.println("Couldn't Ready the SIM.");
79+
return;
80+
}
81+
SerialMon.println("SIM is Ready.");
82+
83+
// high indicates the modem is initialized successfully
84+
digitalWrite(LED_PIN, HIGH);
85+
SerialMon.println("Modem Initialized Successfully !");
86+
87+
SerialMon.println("Waiting for network...");
88+
if(!modem.waitForNetwork()) {
89+
SerialMon.println(" fail");
90+
delay(10000);
91+
return;
92+
}
93+
SerialMon.println(" success");
94+
95+
if(modem.isNetworkConnected()) {
96+
SerialMon.println("Network connected");
97+
}
98+
99+
// GPRS connection parameters are usually set after network registration
100+
SerialMon.print("Connecting to apn : ");
101+
SerialMon.println(apn);
102+
103+
if (!modem.gprsConnect(apn)) {
104+
SerialMon.println(" fail");
105+
delay(10000);
106+
return;
107+
}
108+
SerialMon.println(" success");
109+
110+
if(modem.isGprsConnected()) {
111+
SerialMon.println("GPRS connected");
112+
}
113+
}
114+
115+
// function to sync time from ntp server with predefined credentials
116+
void syncTimeFromNtp() {
117+
String dateTime = modem.getGSMDateTime(DATE_FULL);
118+
119+
SerialMon.print("Current Time : ");
120+
SerialMon.println(dateTime);
121+
SerialMon.println();
122+
}
123+
124+
void setup() {
125+
// put your setup code here, to run once:
126+
SerialMon.begin(9600);
127+
SerialMon.println();
128+
129+
setupModem();
130+
syncTimeFromNtp();
131+
132+
// begin the bytebeam client
133+
Bytebeam.begin(&modem);
134+
135+
// check if OTA is enabled or disabled for your device
136+
bool OTAStatus = Bytebeam.isOTAEnabled();
137+
138+
if(!OTAStatus) {
139+
SerialMon.println("OTA is Disabled.");
140+
} else {
141+
SerialMon.println("OTA is Enabled.");
142+
}
143+
144+
// enable OTA updates for your device
145+
Bytebeam.enableOTA();
146+
147+
// disable OTA updates for your device (default)
148+
// Bytebeam.disableOTA();
149+
150+
SerialMon.printf("Application Firmware Version : %s\n", fwVersion);
151+
}
152+
153+
void loop() {
154+
// put your main code here, to run repeatedly:
155+
156+
// bytebeam client loop
157+
Bytebeam.loop();
158+
159+
// hold on execution for some time
160+
delay(5000);
161+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Bytebeam Basic OTA Via GSM Example
2+
This example will show you how to do over the air firmware upgrades with Bytebeam IoT Platform via GSM.
3+
4+
## Hardware specification
5+
1. ESP32 Dev Board
6+
7+
## Software Specification
8+
1. Bytebeam Arduino Library
9+
2. TinyGSM Library http://librarymanager/#TinyGSM
10+
3. ArduinoHttpClient Library http://librarymanager/#ArduinoHttpClient
11+
4. SSLClient Library https://github.com/govorox/SSLClient.git

examples/ESP32/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
This section includes some basic skecthes to get you started with **BytebeamArduino** on ESP32.
44

55
- SetupClient
6+
- SetupClient_GSM
67
- ActionsHandling
78
- ToggleLED
89
- PushData
910
- PublishChipTemperature
1011
- EspTouch
1112
- UpdateConfig
1213
- CloudLogging
13-
- BasicOTA
14+
- BasicOTA
15+
- BasicOTA_GSM
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Bytebeam Setup GSM Client Example
2+
This example will show you how to setup the GSM client for Bytebeam IoT Platform.
3+
4+
## Hardware specification
5+
1. ESP32 Dev Board
6+
7+
## Software Specification
8+
1. BytebeamArduino Library
9+
2. TinyGSM Library http://librarymanager/#TinyGSM
10+
3. ArduinoHttpClient Library http://librarymanager/#ArduinoHttpClient
11+
4. SSLClient Library https://github.com/govorox/SSLClient.git
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
#define TINY_GSM_MODEM_SIM7600
2+
#include <TinyGsmClient.h>
3+
#include <BytebeamArduino.h>
4+
5+
//
6+
// By including the above header you got the access to the gloabl object named Bytebeam
7+
// Use Bytebeam global object to perform the required operations
8+
//
9+
10+
#define LED_PIN 12
11+
#define MODEM_PWRKEY 4
12+
#define MODEM_FLIGHT 25
13+
#define MODEM_TX 27
14+
#define MODEM_RX 26
15+
16+
// set GSM PIN, if any
17+
#define GSM_PIN ""
18+
19+
#define SerialMon Serial
20+
#define SerialAT Serial1
21+
22+
// Your GPRS credentials, if any
23+
const char apn[] = "";
24+
const char gprsUser[] = "";
25+
const char gprsPass[] = "";
26+
27+
TinyGsm modem(SerialAT);
28+
29+
// function to setup the modem with predefined credentials
30+
void setupModem() {
31+
// configure your reset, enable pins here if needed
32+
pinMode(LED_PIN, OUTPUT);
33+
pinMode(MODEM_PWRKEY, OUTPUT);
34+
pinMode(MODEM_FLIGHT, OUTPUT);
35+
36+
// set the status led pin low to indicate the start process
37+
digitalWrite(LED_PIN, LOW);
38+
39+
// pull up power pin (IO:4) Modulator power key, need to powered up the modem
40+
// this pin must be held high for more than 1 second according to manual requirements
41+
digitalWrite(MODEM_PWRKEY, LOW);
42+
delay(100);
43+
digitalWrite(MODEM_PWRKEY, HIGH);
44+
delay(1000);
45+
digitalWrite(MODEM_PWRKEY, LOW);
46+
47+
// pull up the power pin (IO:25) Modulator flight mode control, need to enable modulator
48+
// this pin must be set to high
49+
digitalWrite(MODEM_FLIGHT, HIGH);
50+
51+
SerialMon.println("Modem Powered ON");
52+
53+
// start the serial communication b/w esp32 and modem
54+
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
55+
delay(6000);
56+
57+
// Restart takes quite some time
58+
// To skip it, call init() instead of restart()
59+
modem.restart();
60+
// modem.init();
61+
62+
// set the network mode (2 : Automatic)
63+
modem.setNetworkMode(2);
64+
65+
String modemName = modem.getModemName();
66+
SerialMon.printf("Modem Name : ");
67+
SerialMon.println(modemName);
68+
69+
String modemInfo = modem.getModemInfo();
70+
SerialMon.print("Modem Info : ");
71+
SerialMon.println(modemInfo);
72+
73+
// Unlock your SIM card with a PIN if needed
74+
if(GSM_PIN && modem.getSimStatus() != 3) {
75+
modem.simUnlock(GSM_PIN);
76+
}
77+
78+
SimStatus simStatus = modem.getSimStatus();
79+
80+
if(simStatus != SIM_READY) {
81+
SerialMon.println("Couldn't Ready the SIM.");
82+
return;
83+
}
84+
SerialMon.println("SIM is Ready.");
85+
86+
// high indicates the modem is initialized successfully
87+
digitalWrite(LED_PIN, HIGH);
88+
SerialMon.println("Modem Initialized Successfully !");
89+
90+
SerialMon.println("Waiting for network...");
91+
if(!modem.waitForNetwork()) {
92+
SerialMon.println(" fail");
93+
delay(10000);
94+
return;
95+
}
96+
SerialMon.println(" success");
97+
98+
if(modem.isNetworkConnected()) {
99+
SerialMon.println("Network connected");
100+
}
101+
102+
// GPRS connection parameters are usually set after network registration
103+
SerialMon.print("Connecting to apn : ");
104+
SerialMon.println(apn);
105+
106+
if (!modem.gprsConnect(apn)) {
107+
SerialMon.println(" fail");
108+
delay(10000);
109+
return;
110+
}
111+
SerialMon.println(" success");
112+
113+
if(modem.isGprsConnected()) {
114+
SerialMon.println("GPRS connected");
115+
}
116+
}
117+
118+
// function to sync time from ntp server with predefined credentials
119+
void syncTimeFromNtp() {
120+
String dateTime = modem.getGSMDateTime(DATE_FULL);
121+
122+
SerialMon.print("Current Time : ");
123+
SerialMon.println(dateTime);
124+
SerialMon.println();
125+
}
126+
127+
void setup() {
128+
// put your setup code here, to run once:
129+
SerialMon.begin(9600);
130+
SerialMon.println();
131+
132+
setupModem();
133+
syncTimeFromNtp();
134+
135+
//
136+
// Your other application setup stuff goes here
137+
//
138+
139+
// This method will initialize and start the bytebeam client
140+
Bytebeam.begin(&modem);
141+
142+
//
143+
// If above call is successfull then your bytebeam client is now configured for the use
144+
// You can always check for the logs in serial monitor for the status of the above call
145+
//
146+
147+
// check if bytebeam client is initialized or deinitialized
148+
bool beginStatus = Bytebeam.isBegined();
149+
150+
if(!beginStatus) {
151+
SerialMon.println("Bytebeam Client is Deinitialized.");
152+
} else {
153+
SerialMon.println("Bytebeam Client is Initialized.");
154+
}
155+
156+
// check if bytebeam client is connected or disconnected
157+
bool connectionStatus = Bytebeam.isConnected();
158+
159+
if(!connectionStatus) {
160+
SerialMon.println("Bytebeam Client is Disconnected.");
161+
} else {
162+
SerialMon.println("Bytebeam Client is Connected.");
163+
}
164+
165+
// Call the end method to stop and de-initialize the bytebeam client at any point of time in the code
166+
// Bytebeam.end();
167+
}
168+
169+
void loop() {
170+
// put your main code here, to run repeatedly:
171+
172+
//
173+
// Your application regular stuff goes here
174+
//
175+
176+
// This method will let you maintain the connection with the bytebeam cloud, In case
177+
// the connection is lost, it will attempt to reconnect to the bytebeam cloud
178+
Bytebeam.loop();
179+
180+
// software delay, you can customize it as per your application needs
181+
delay(5000);
182+
}

0 commit comments

Comments
 (0)