forked from RAKWireless/WisBlock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BG77_Unvarnished_Transmission.ino
91 lines (87 loc) · 1.61 KB
/
BG77_Unvarnished_Transmission.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
@file BG77_Unvarnished_Transmission.ino
@author rakwireless.com
@brief BG77 unvarnished transmission via USB
@version 0.1
@date 2020-12-28
@copyright Copyright (c) 2020
**/
#define BG77_POWER_KEY WB_IO1
void setup()
{
time_t serial_timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - serial_timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("BG77 AT CMD TEST!");
// Check if the modem is already awake
time_t timeout = millis();
bool moduleSleeps = true;
Serial1.begin(115200);
delay(1000);
Serial1.println("ATI");
//BG77 init
while ((millis() - timeout) < 6000)
{
if (Serial1.available())
{
String result = Serial1.readString();
Serial.println("Modem response after start:");
Serial.println(result);
moduleSleeps = false;
}
}
if (moduleSleeps)
{
// Module slept, wake it up
pinMode(BG77_POWER_KEY, OUTPUT);
digitalWrite(BG77_POWER_KEY, 0);
delay(1000);
digitalWrite(BG77_POWER_KEY, 1);
delay(2000);
digitalWrite(BG77_POWER_KEY, 0);
delay(1000);
}
Serial.println("BG77 power up!");
}
void loop()
{
int timeout = 100;
String resp = "";
String snd = "";
char cArr[128] = {0};
while (timeout--)
{
if (Serial1.available() > 0)
{
resp += char(Serial1.read());
}
if (Serial.available() > 0)
{
snd += char(Serial.read());
}
delay(1);
}
if (resp.length() > 0)
{
Serial.print(resp);
}
if (snd.length() > 0)
{
memset(cArr, 0, 128);
snd.toCharArray(cArr, snd.length() + 1);
Serial1.write(cArr);
delay(10);
}
resp = "";
snd = "";
}