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