46 #include "em_device.h" 59 #define PRINT_ID_TOKEN 0 88 #if PRINT_ID_TOKEN == 1 89 #if DEBUG_DBPRINT == 1 92 dbprint(
"INFO: DEVICE_ID_hex = ");
95 dbprint(
"INFO: DEVICE_TOKEN = ");
97 dbprint(
"INFO: DEVICE_TOKEN_hex = ");
104 CMU_ClockEnable(cmuClock_GPIO,
true);
127 USART_InitAsync_TypeDef config = USART_INITASYNC_DEFAULT;
130 if (
BG96_UART == USART0) CMU_ClockEnable(cmuClock_USART0,
true);
131 else if (
BG96_UART == USART1) CMU_ClockEnable(cmuClock_USART1,
true);
139 GPIO_PinModeSet(gpioPortE, 11, gpioModeInput, 0);
140 GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 1);
143 GPIO_PinModeSet(gpioPortC, 10, gpioModeInput, 0);
147 GPIO_PinModeSet(gpioPortE, 12, gpioModeInput, 0);
148 GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 1);
151 GPIO_PinModeSet(gpioPortB, 8, gpioModeInput, 0);
152 GPIO_PinModeSet(gpioPortB, 7, gpioModePushPull, 1);
156 GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
157 GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
168 GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0);
169 GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1);
173 GPIO_PinModeSet(gpioPortD, 6, gpioModeInput, 0);
174 GPIO_PinModeSet(gpioPortD, 7, gpioModePushPull, 1);
177 GPIO_PinModeSet(gpioPortA, 0, gpioModeInput, 0);
178 GPIO_PinModeSet(gpioPortF, 2, gpioModePushPull, 1);
181 GPIO_PinModeSet(gpioPortC, 2, gpioModeInput, 0);
182 GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 1);
196 BG96_UART->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC0;
199 BG96_UART->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC1;
202 BG96_UART->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC2;
205 BG96_UART->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC3;
208 BG96_UART->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC4;
211 BG96_UART->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC5;
214 BG96_UART->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC6;
217 BG96_UART->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_DEFAULT;
238 #if DEBUG_DBPRINT == 1 239 dbprintln(
"INFO: Sending the following values to the cloud:");
357 #if DEBUG_DBPRINT == 1 420 #if DEBUG_DBPRINT == 1 451 if (number == 0)
sendCMD(
"a162703119");
452 else if (number == 1)
sendCMD(
"a162703219");
481 #if DEBUG_DBPRINT == 1 482 dbinfo(
"Powering on BG96");
493 #if DEBUG_DBPRINT == 1 494 dbinfo(
"Sending Activate PDP command...");
500 while (!continueCode)
512 #if DEBUG_DBPRINT == 1 513 dbinfo(
"Sending Create UDP command...");
516 sendCMD(
"AT+QIOPEN=1,0,\"UDP\",\"40.68.172.187\",8891\r");
521 return (continueCode);
541 #if DEBUG_DBPRINT == 1 542 dbinfo(
"Sending Deactivate PDP command...");
551 #if DEBUG_DBPRINT == 1 552 dbinfo(
"Sending Power down command...");
562 #if DEBUG_DBPRINT == 1 563 dbwarn(
"Powering down BG96 using hardware...");
571 return (continueCode);
595 #if DEBUG_DBPRINT == 1 596 dbinfo(
"Sending Disable Echo command...");
599 bool continueCode =
true;
603 while (!continueCode)
627 for (
uint32_t i = 0; message[i] != 0; i++)
654 if (localBuffer ==
'\n')
662 buf[i] = localBuffer;
718 #if DEBUG_DBPRINT == 1
void dbprint(char *message)
Print a string (char array) to USARTx.
void dbprintlnInt(int32_t value)
Print a number in decimal notation to USARTx and go to the next line.
void sendMeasurements(MeasurementData_t *data)
Send measurements to the cloud using NB-IoT.
static bool transmissionEnd(bool continueCode)
Code for the end of a NB-IoT transmission.
void dbprintln(char *message)
Print a string (char array) to USARTx and go to the next line.
void powerBG96(void)
Method to enable the power key for 100ms to enable/disable the module.
signed char int8_t
Typedef defining 8 bit char type. The developer should modify this to suit the platform being deploye...
Definitions of the custom data-types used.
void dbwarn(char *message)
Print a warning string (char array) in yellow to USARTx and go to the next line.
void sendStatus(int8_t status)
Send status to the cloud using NB-IoT.
String (char array) conversion functionality.
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
void charASCII_to_charHex(char *inbuf, char *outbuf)
Convert an ASCII char array (string) to a hexadecimal char array.
bool stringStartsWith(char *inbuf, char *sequence)
Check if a given char array (string) starts with a given sequence.
void readResponse(char *buf)
Read a string (char array) from USARTx.
void sendCMD(char *message)
Print a string (char array) to USARTx.
char DEVICE_ID_hex[2 *(sizeof(DEVICE_ID) -1)+1]
bool waitForResponse(char *response, uint8_t timeout)
Wait for the correct response using sleep/timeout functionality.
Header file containing DEVICE_ID and DEVICE_ID.
The pin definitions for the custom board.
static bool transmissionBegin(bool continueCode)
Code for the start of a NB-IoT transmission.
Enable or disable printing to UART with dbprint.
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
BG96 AT-command driver functionality.
void dbprintInt(int32_t value)
Print a number in decimal notation to USARTx.
void initBG96(void)
Initialize the GPIO pins and UART0 module necessary to communicate with the BG96 module.
void sleep(uint32_t sSleep)
Sleep for a certain amount of seconds in EM2/3.
char DEVICE_TOKEN_hex[2 *(sizeof(DEVICE_TOKEN) -1)+1]
static void uint32_to_charHex(char *buf, uint32_t value, bool spacing)
Convert a uint32_t value to a hexadecimal char array (string).
void sendPulse(uint8_t number, uint8_t pulse)
Send current pulses to the cloud using NB-IoT.
void dbprint_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
void disableEcho(void)
Disable echo.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type. The developer should modify this to suit the platform bein...