Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Arduino.h"
- #define USB SerialUSB
- #define UBLOX Serial1
- // Pin to turn on/off the nb-iot module
- #define powerPin 7
- #define commands 17
- String atcommands[commands] = { "ATE0",
- "AT+URAT=7",
- "AT+URAT?",
- "AT+CMEE=2",
- "AT+CGDCONT=1,\"IP\",\"internet.m2m\"",
- "AT+CGDCONT?",
- "AT+CFUN=1",
- "AT+COPS=1,2,\"20408\"",
- "AT+CSQ",
- "AT+CREG=2",
- "AT+CREG?",
- "AT+CGPADDR",
- "AT+CMGF=1",
- "AT+CMGL",
- "AT+USOCR=17",
- "AT+USOST=0,\"YOURIP\",YOURPORT,4,\"Data\"",
- "AT+USOCL=0"
- };
- int pos = 0;
- void setup()
- {
- // Turn the nb-iot module on
- //pinMode(powerPin, OUTPUT);
- //digitalWrite(powerPin, HIGH);
- pinMode(SARA_ENABLE, OUTPUT);
- pinMode(SARA_TX_ENABLE, OUTPUT);
- digitalWrite(SARA_ENABLE, HIGH); // enable power to ublox
- digitalWrite(SARA_TX_ENABLE, HIGH);
- pinMode(SARA_R4XX_TOGGLE, OUTPUT);
- digitalWrite(SARA_R4XX_TOGGLE, LOW);
- // Start communication
- USB.begin(115200);
- UBLOX.begin(115200); //ublox should always be 9600
- delay(4000);
- USB.println("type an AT command or type m for Menu of commands");
- delay(1000);
- //clear UBLOX buffer
- while (UBLOX.available()) {
- UBLOX.read();
- }
- }
- void loop()
- {
- int len = 160; // allow commands up to 160 characters
- char buffer[len];
- int commandFound = 0;
- if (USB.available())
- {
- uint8_t c = USB.read();
- if (pos == 0 && c == 'm')
- {
- for (int x = 0 ; x < commands ; x++) {
- USB.print(x + 1);
- if (x < 9) {
- USB.print(" ");
- } else
- {
- USB.print(" ");
- }
- USB.println(atcommands[x]);
- }
- USB.println("you can use one of the above shortcodes, just type the number and press enter");
- buffer[0] = 0;
- } else
- {
- switch (c) {
- case '\n': // Ignore new-lines
- break;
- case '\r': // Return on CR
- commandFound = 1;
- break;
- default:
- USB.write(c); //display what is typed
- if (pos < len - 1) {
- buffer[pos++] = c;
- buffer[pos] = 0;
- }
- }
- if (commandFound ) {
- String inputline(buffer);
- int menuchoice = inputline.toInt();
- USB.println();
- if (menuchoice > 0) {
- inputline = atcommands[menuchoice - 1];
- USB.println(inputline);
- }
- UBLOX.println(inputline);
- commandFound = 0;
- pos = 0;
- }
- }
- }
- while (UBLOX.available())
- {
- USB.write(UBLOX.read());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement