forked from wiaio/nb-iot-utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintial_config.ino
54 lines (43 loc) · 1017 Bytes
/
intial_config.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
#include "Arduino.h"
#if defined(ARDUINO_AVR_LEONARDO)
#define USB Serial
#define UBLOX Serial1
#elif defined(ARDUINO_SODAQ_EXPLORER)
#define USB SerialUSB
#define UBLOX Serial
#elif defined(ARDUINO_SAM_ZERO)
#define USB SerialUSB
#define UBLOX Serial1
#else
#error "Please select a Sodaq ExpLoRer, Arduino Leonardo or Arduino m0."
#endif
// Pin to turn on/off the nb-iot module
#define powerPin 7
unsigned long baud = 9600; //start at 9600 allow the USB port to change the Baudrate
void setup()
{
// Turn the nb-iot module on
pinMode(powerPin, OUTPUT);
digitalWrite(powerPin, HIGH);
// Start communication
USB.begin(baud);
UBLOX.begin(baud);
}
// Forward every message to the other serial
void loop()
{
while (USB.available())
{
uint8_t c = USB.read();
UBLOX.write(c);
}
while (UBLOX.available())
{
USB.write(UBLOX.read());
}
// check if the USB virtual serial wants a new baud rate
if (USB.baud() != baud) {
baud = USB.baud();
UBLOX.begin(baud);
}
}