diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..acec2b7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+src/.idea
diff --git a/src/.idea/misc.xml b/src/.idea/misc.xml
deleted file mode 100644
index 79b3c94..0000000
--- a/src/.idea/misc.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/src/.idea/modules.xml b/src/.idea/modules.xml
deleted file mode 100644
index f669a0e..0000000
--- a/src/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/.idea/src.iml b/src/.idea/src.iml
deleted file mode 100644
index f08604b..0000000
--- a/src/.idea/src.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/src/.idea/workspace.xml b/src/.idea/workspace.xml
deleted file mode 100644
index 5acf9fc..0000000
--- a/src/.idea/workspace.xml
+++ /dev/null
@@ -1,355 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- readResponse
- ::readResponse
- wdt
- println
-
-
-
-
-
-
-
-
-
-
-
- true
- DEFINITION_ORDER
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1507878788635
-
-
- 1507878788635
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Sodaq_nbIOT.cpp b/src/Sodaq_nbIOT.cpp
index c635322..adedeb5 100644
--- a/src/Sodaq_nbIOT.cpp
+++ b/src/Sodaq_nbIOT.cpp
@@ -120,7 +120,7 @@ Sodaq_nbIOT::Sodaq_nbIOT() :
// Returns true if the modem replies to "AT" commands without timing out.
bool Sodaq_nbIOT::isAlive() {
-// _disableDiag = true;
+ _disableDiag = true;
println(STR_AT);
// @todo check if necessary
delay(150);
@@ -463,7 +463,7 @@ bool Sodaq_nbIOT::connectSocket() {
// return false;
// }
-// reboot();
+ reboot();
//
// if (!on()) {
// return false;
@@ -533,7 +533,7 @@ ResponseTypes Sodaq_nbIOT::_createSocketParser(ResponseTypes &response, const ch
return ResponseError;
}
-bool Sodaq_nbIOT::sendSocket(uint8_t socket, const char *host, uint16_t port, const char *buffer, size_t size) {
+int Sodaq_nbIOT::sendSocket(uint8_t socket, const char *host, uint16_t port, const char *buffer, size_t size) {
print("AT+NSOST=");
print(socket);
print(",");
@@ -549,10 +549,12 @@ bool Sodaq_nbIOT::sendSocket(uint8_t socket, const char *host, uint16_t port, co
}
println();
- delay(AT_CMD_SLEEP_TIME);
-
uint8_t sent;
- return readResponse(_sendSocketParser, NULL, &sent) == ResponseOK && sent > 0;
+ if(readResponse(_sendSocketParser, &socket, &sent) == ResponseOK) {
+ return sent;
+ }
+
+ return -1;
}
ResponseTypes Sodaq_nbIOT::_sendSocketParser(ResponseTypes &response, const char *buffer, size_t size,
@@ -564,11 +566,12 @@ ResponseTypes Sodaq_nbIOT::_sendSocketParser(ResponseTypes &response, const char
int value;
int value2;
- if (sscanf(buffer, "%d,%d", &value, &value2) == 1) {
+ if (sscanf(buffer, "%d,%d", &value, &value2) == 2) {
*sent = value2;
return ResponseEmpty;
}
+ SerialUSB.println(F(__FILE__"sockparserr"));
return ResponseError;
}
@@ -578,10 +581,13 @@ size_t Sodaq_nbIOT::socketReceive(uint8_t socket, char *buffer, size_t size) {
print(socket);
print(",");
println(size);
+ debugPrintLn(F(__FILE__": socketReceive() sent"));
if (readResponse(_socketReceiveParser, &socket, buffer, &size) == ResponseOK) {
+ debugPrintLn(__FILE__": socketReceive() OK");
return size;
}
+ debugPrintLn(__FILE__": socketReceive() ERR");
return 0;
}
@@ -591,17 +597,38 @@ ResponseTypes Sodaq_nbIOT::_socketReceiveParser(ResponseTypes &response, const c
return ResponseError;
}
+ int tmp_sock = 0;
+ char tmp_ip[16] = "";
+ int tmp_port = 0;
+ int tpm_length = 0;
+ int tpm_length_rem = 0;
+
+
+
+ SerialUSB.println(__FILE__": _socketReceiveParser() sscanf");
// ,,,,,
- if (sscanf(buffer, "%d,%s,%d,%d,%s,%d", NULL, NULL, NULL, NULL, parsedBuffer, NULL) == 1) {
+ SerialUSB.println(__FILE__": _socketReceiveParser() buffer:");
+ SerialUSB.println(buffer);
+ // create a result buffer for the HEX string input
+ auto * resultBuffer = static_cast(malloc(250));
+ memset(resultBuffer,0,250);
+ if (sscanf(buffer, "%d,%[^,],%d,%d,%[^,],%d", &tmp_sock, tmp_ip, &tmp_port, &tpm_length, resultBuffer, &tpm_length_rem) == 6) {
+ SerialUSB.println(__FILE__": _socketReceiveParser() OK");
+ int i;
+ for(i=0; i < tpm_length;i++) {
+ parsedBuffer[i] = HEX_PAIR_TO_BYTE(resultBuffer[i*2], resultBuffer[i*2+1]);
+ }
+// parsedBuffer[i*2] = 0;
return ResponseEmpty;
}
+ SerialUSB.println(__FILE__": _socketReceiveParser() ERR");
return ResponseError;
}
size_t Sodaq_nbIOT::socketBytesPending(uint8_t socket) {
- int count = readLn(_inputBuffer, _inputBufferSize, 250);
+ int count = readLn(_inputBuffer, _inputBufferSize, 1000);
if (count == 0) {
return 0;
diff --git a/src/Sodaq_nbIOT.h b/src/Sodaq_nbIOT.h
index 8a13bef..cca0d20 100644
--- a/src/Sodaq_nbIOT.h
+++ b/src/Sodaq_nbIOT.h
@@ -75,7 +75,7 @@ class Sodaq_nbIOT: public Sodaq_AT_Device
bool connectSocket();
int createSocket(uint16_t localPort = 0);
- bool sendSocket(uint8_t socket, const char *host, uint16_t port, const char *buffer, size_t size);
+ int sendSocket(uint8_t socket, const char *host, uint16_t port, const char *buffer, size_t size);
size_t socketReceive(uint8_t socket, char* buffer, size_t size);
size_t socketBytesPending(uint8_t socket);
bool closeSocket(uint8_t socket);