https://github.com/pilotak/tcplogs
https://github.com/pilotak/tcplogs
Last synced: 16 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/pilotak/tcplogs
- Owner: pilotak
- License: mit
- Created: 2018-12-06T10:45:23.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-22T09:20:14.000Z (over 3 years ago)
- Last Synced: 2025-03-06T08:20:44.631Z (over 1 year ago)
- Language: C++
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TCPLogs
```cpp
#include "mbed.h"
#include "UbloxATCellularInterfaceExt.h"
#include "TCPLogs.h"
UbloxATCellularInterfaceExt mdm(PD_5, PD_6, 115200, false);
TCPLogs logs;
const char* server = "text.com";
const int port = 12345;
uint8_t data[8] = {0};
bool serverConnect() {
if (logs.connect() == NSAPI_ERROR_OK) {
return true;
} else {
printf("Socket connect FAILED\n");
}
return false;
}
int main() {
printf("Start\n");
if (mdm.init()) {
printf("mdm init OK\n");
logs.network(mdm);
if (mdm.connect() == NSAPI_ERROR_OK) {
printf("mdm connect OK\n");
printf("Connecting to %s: %d\r\n", server, port);
logs.set_server(server, port);
if (serverConnect()) {
while (1) {
if (logs.is_connected()) {
printf("sending\n");
int size = snprintf(data, sizeof(data), "test");
logs.log(data, size);
} else {
serverConnect();
}
ThisThread::sleep_for(5s);
}
}
} else {
printf("mdm connect FAILED\n");
}
} else {
printf("mdm init FAILED\n");
}
}
```