commit 1e163c3cf60a035f0243a8e75ef326ea490dd3f9
parent de26b1a3aec1351330894659b4bd372da4423f65
Author: Friedel <[email protected]>
Date: Fri, 10 Jun 2022 00:19:26 +0200
bring some beauty into the console + adding "ignoring"-command
Diffstat:
4 files changed, 46 insertions(+), 28 deletions(-)
diff --git a/5g-client/5g-board.ino b/5g-client/5g-board.ino
@@ -21,7 +21,7 @@ void setup() {
// -*- module initialization -*-
- usbSerial.print("[INFO] waiting for module to start up");
+ usbSerial.print(prefixInfo "waiting for module to start up");
for (;;) {
usbSerial.print('.');
modemSerial.write("AT\r\n");
@@ -35,31 +35,31 @@ void setup() {
sendCommand("ATE0"); // disable command-echo
- char info[256];
- sendCommand("ATI", info);
-
- usbSerial.println("[INFO] module information:");
- usbSerial.println(info);
-
// if (sendCommand("AT+CPIN=\"" SIM_PIN "\"") == COMMAND_ERROR) {
// usbSerial.println("[EROR] sim can't be unlocked, wrong PIN");
// return;
// }
- usbSerial.println("[INFO] sim successful unlocked");
+ usbSerial.println(prefixInfo "sim successful unlocked");
sendCommand("AT+CPSMS=0"); // Disable Power Saving Mode
sendCommand("AT+CEDRXS=0"); // Disable eDRX
- usbSerial.println("[INFO] disabled power safe");
+ usbSerial.println(prefixInfo "disabled power safe");
// -*- internet initialization -*-
- sendCommand("AT+CFUN=15", COMMAND_BLOCK); // Reset the module
- sendCommand("AT+UMNOPROF=1", COMMAND_BLOCK); // Set MNO profile (1=automatic,100=standard europe)
- sendCommand("AT+URAT=7,8"); // Set URAT to LTE-M/NB-IOT
- sendCommand("AT+CEREG=3", COMMAND_BLOCK); // Enable URCs
+ char info[100];
+
+ sendCommand("AT+CFUN=15", COMMAND_BLOCK); // Reset the module
+ sendCommand("AT+UMNOPROF=1", COMMAND_BLOCK); // Set MNO profile (1=automatic,100=standard europe)
+ sendCommand("AT+URAT?", info);
+ usbSerial.print(prefixInfo "urat: ");
+ usbSerial.println(info);
+ sendCommand("AT+URAT=8", COMMAND_IGNORE); // Set URAT to LTE-M/NB-IOT
+ sendCommand("AT+CEREG=3", COMMAND_IGNORE); // Enable URCs
sendCommand("AT+CGDCONT=1,\"IP\",\"" simAPN "\"", COMMAND_BLOCK); // Set the APN
- sendCommand("AT+COPS=0,2"); // Autoselect the operator
+ sendCommand("AT+CFUN=1"); // enable radio
+ sendCommand("AT+COPS=0,2", COMMAND_BLOCK); // Autoselect the operator
- usbSerial.print("[INFO] waiting for connection");
+ usbSerial.print(prefixInfo "waiting for connection");
char response[100];
@@ -76,7 +76,7 @@ void setup() {
}
usbSerial.println();
- usbSerial.println("[INFO] connected!");
+ usbSerial.println(prefixInfo "connected!");
// -*- server connection -*-
@@ -94,7 +94,7 @@ AT+UHTTPC=0,5,"/api/search_connect","","TEST!",1
sendCommand("AT+UHTTPC=0,5,\"/api/search_connect\",\"\",\"TEST!\",1");
- usbSerial.println("[INFO] initiation completed, starting passthrough:");
+ usbSerial.println(prefixInfo "initiation completed, starting passthrough:");
}
void loop() {
diff --git a/5g-client/command.h b/5g-client/command.h
@@ -11,7 +11,8 @@ enum command_flags {
COMMAND_NONE, // none of them underneath
COMMAND_SILENT = 1 << 0, // no debug messages (for looped commands)
COMMAND_BLOCK = 1 << 1, // no time-out (for waiting commands)
- COMMAND_EVENT = 1 << 2, // handle '+'-responses as event
+ COMMAND_IGNORE = 1 << 2, // don't wait for response, just wait $ignoreDelay secounds
+ COMMAND_EVENT = 1 << 3, // handle '+'-responses as event
};
// -*- declarations -*-
diff --git a/5g-client/command.ino b/5g-client/command.ino
@@ -9,6 +9,7 @@ command_status sendCommand(const char* request, char* response, command_flags fl
bool silent = flags & COMMAND_SILENT,
block = flags & COMMAND_BLOCK,
+ ignore = flags & COMMAND_IGNORE,
event_handle = flags & COMMAND_EVENT;
if (response)
@@ -22,7 +23,7 @@ command_status sendCommand(const char* request, char* response, command_flags fl
modemSerial.flush();
if (blockDebug && block && !silent) {
- usbSerial.print("[DBUG] command '");
+ usbSerial.print(prefixDebug "command '");
usbSerial.print(request);
usbSerial.println("' is blocking");
}
@@ -32,9 +33,16 @@ command_status sendCommand(const char* request, char* response, command_flags fl
for (;;) {
while (!modemSerial.available()) {
now = millis();
- if (!block && now - start > commandTimeout * 1000) {
+ if (ignore && now - start > ignoreDelay * 1000) {
if (commandDebug && !silent) {
- usbSerial.print("[WARN] command '");
+ usbSerial.print(prefixDebug "command '");
+ usbSerial.print(request);
+ usbSerial.println("' succeed (ignoring response)");
+ }
+ return COMMAND_TIMEOUT;
+ } else if (!ignore && !block && now - start > commandTimeout * 1000) {
+ if (commandDebug && !silent) {
+ usbSerial.print(prefixWarn "command '");
usbSerial.print(request);
usbSerial.println("' timed out");
}
@@ -52,27 +60,27 @@ command_status sendCommand(const char* request, char* response, command_flags fl
if (String(line) == "OK") {
if (commandDebug && !silent) {
- usbSerial.print("[DBUG] command '");
+ usbSerial.print(prefixDebug "command '");
usbSerial.print(request);
usbSerial.println("' succeed");
}
return COMMAND_OK;
} else if (strstr(line, "ERROR")) {
if (commandDebug && !silent) {
- usbSerial.print("[WARN] command '");
+ usbSerial.print(prefixError "command '");
usbSerial.print(request);
usbSerial.println("' failed");
}
return COMMAND_ERROR;
} else if (event_handle && line[0] == '+') {
if (eventDebug && !silent) {
- usbSerial.print("[EVNT] event '");
+ usbSerial.print(prefixEvent "event '");
usbSerial.print(line);
usbSerial.println(" caused'");
}
} else if (line[0] != '\0' && strcmp(request, line)) {
if (lineDebug && !silent) {
- usbSerial.print("[LINE] ");
+ usbSerial.print(prefixLine);
usbSerial.print(request);
usbSerial.print(" -> '");
usbSerial.print(line);
diff --git a/5g-client/config.h b/5g-client/config.h
@@ -1,5 +1,13 @@
#pragma once
+// -*- prefixes -*-
+#define prefixInfo "info | "
+#define prefixDebug "debug | "
+#define prefixError "error | "
+#define prefixLine "line | "
+#define prefixWarn "warn | "
+#define prefixEvent "event | "
+
// -*- hardware stuff -*-
#define usbSerial SerialUSB
#define modemSerial Serial1
@@ -7,12 +15,12 @@
#define enablePin SARA_TX_ENABLE
#define voltagePin SARA_R4XX_TOGGLE
-
// -*- behaviour settings -*-
#define baud 115200 // baut-rate of modem-/usb-serial
-#define lineBuffer 256 // buffer-size (bytes) to use to store lines
+#define lineBuffer 512 // buffer-size (bytes) to use to store lines
#define commandTimeout 10.0 // seconds to cancel a command
#define commandDelay 0.1 // delay after every command
+#define ignoreDelay 2 // seconds to wait if command is run with COMMAND_IGNORE
#define commandDebug true // send debug information about command requests
#define eventDebug true // print '+'-events
#define lineDebug false // print each line to debug
@@ -21,4 +29,4 @@
// -*- sim settings -*-
#define simPin "0000" // PIN of the sim
-#define simAPN "lpwa.vodafone.iot" // APN-network of the sim
+#define simAPN "lpwa.vodafone.iot" // APN-network of the sim
+\ No newline at end of file