There are a few things:
I’m pretty sure TCP doesn’t work right on the Boron on 0.8.0-rc.26. In my test it would only send the first buffer of data then stall.
However, I ran the same code on an E Series LTE (running 0.8.0-rc.11, same SARA-R410M-02-B modem). I get a consistent 1792 bytes/sec. So 10 Kbits/sec would appear to be possible.
0000016410 [app] INFO: sent 8960 bytes in 5 sec (1792 bytes/sec), 0 % complete
0000021416 [app] INFO: sent 17920 bytes in 10 sec (1792 bytes/sec), 1 % complete
0000026422 [app] INFO: sent 26880 bytes in 15 sec (1792 bytes/sec), 2 % complete
0000031428 [app] INFO: sent 35840 bytes in 20 sec (1792 bytes/sec), 3 % complete
0000036434 [app] INFO: sent 44800 bytes in 25 sec (1792 bytes/sec), 4 % complete
0000041440 [app] INFO: sent 53760 bytes in 30 sec (1792 bytes/sec), 5 % complete
The Nordic nRF52840 MCU on the Boron is a little slower than the STM32F205 on the E Series, but I think you’ll be bound by the network speed, not CPU speed.
Here’s the code:
#include "Particle.h"
SerialLogHandler logHandler;
SYSTEM_THREAD(ENABLED);
uint16_t START_PIN = D2;
enum {
WAIT_STATE = 0,
START_STATE,
SEND_STATE
};
const IPAddress remoteHost = IPAddress(65, 19, 178, 42);
const uint16_t remotePort = 7123;
const size_t transmissionSize = 1024 * 1024; // must be a multiple of writeSize
const size_t writeSize = 256;
const unsigned long reportTimePeriodMs = 5000;
int state = WAIT_STATE;
unsigned long stateTime = 0;
unsigned long reportTime = 0;
uint8_t buffer[writeSize];
size_t transmissionOffset = 0;
TCPClient client;
void reportProgress();
void setup() {
pinMode(START_PIN, INPUT_PULLUP);
char c = 'a';
for(size_t ii = 0; ii < writeSize; ii++) {
buffer[ii] = c++;
if (c > 'z') {
c = 'a';
}
}
}
void loop() {
if (digitalRead(START_PIN) == 0) {
if (state == WAIT_STATE && Network.ready()) {
state = START_STATE;
}
}
switch(state) {
case WAIT_STATE:
break;
case START_STATE:
if (client.connect(remoteHost, remotePort)) {
Log.info("Connected to %s:%d!", remoteHost.toString().c_str(), remotePort);
state = SEND_STATE;
stateTime = reportTime = millis();
}
else {
Log.info("failed to connect to %s:%d", remoteHost.toString().c_str(), remotePort);
state = WAIT_STATE;
}
break;
case SEND_STATE:
// Prepare a buffer
snprintf((char *)buffer, writeSize, "|%08x", transmissionOffset);
// Send it
//Log.info("writing %u", writeSize);
{
int res = client.write(buffer, writeSize);
if (res > 0) {
//Log.info("write complete %u res=%d", writeSize, res);
transmissionOffset += writeSize;
if (transmissionOffset >= transmissionSize) {
reportProgress();
client.stop();
state = WAIT_STATE;
}
}
else {
Log.info("write failure transmissionOffset=%u res=%d", transmissionOffset, res);
client.stop();
state = WAIT_STATE;
}
}
if (millis() - reportTime >= reportTimePeriodMs) {
reportTime = millis();
reportProgress();
}
break;
}
}
void reportProgress() {
int pctComplete = transmissionOffset * 100 / transmissionSize;
size_t elapsedSec = (millis() - stateTime) / 1000;
Log.info("sent %u bytes in %u sec (%u bytes/sec), %d %% complete",
transmissionOffset, elapsedSec, transmissionOffset / elapsedSec, pctComplete);
}