Very interesting! Thank you for posting this alternative.
But I'm not sure where you get the 4 transactions per second? There may be things you can do with the Bridge (like synchronously run a long Process) that might be that slow, but the code you posted is essentially a replacement for the Console class, and I've never seen it be that slow. I've slightly modified your code to use the Console class (added Bridge.begin() and Console.begin() instead of Serial1.begin()) and changed all other instances of Serial1 to Console. When I run that code, I get 34 lines per second.
Yes, 34 lines per second is slower than 878 lines per second, but we can't make a direct comparison without repeating your test above on my setup. This is necessary because there are other variables at play besides the raw serial port speed, for example, the SSH output is going over our local networks and being read and displayed by our SSH clients - your network and client might be running at a very different speed than mine, and may have very different network loading.
So to have a meaningful comparison, I tried running your example, and I got hung up on the first step:
root@Yun4:~# opkg update
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/Packages.gz.
Updated list of available packages in /var/opkg-lists/attitude_adjustment.
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/Packages.sig.
Signature check passed.
root@Yun4:~# opkg install ser2net
Installing ser2net (2.7-2) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/ser2net_2.7-2_ar71xx.ipk.
Collected errors:
* opkg_download: Failed to download http://downloads.arduino.cc/openwrtyun/1/packages/ser2net_2.7-2_ar71xx.ipk: Error.
* opkg_install_pkg: Failed to download ser2net. Perhaps you need to run 'opkg update'?
* opkg_install_cmd: Cannot install package ser2net.
root@Yun4:~#
Being unable to duplicate your test, we can't draw any valid conclusions. I'm willing to concede that the Bridge Console is going to be slower than ser2net, but I contend that the difference is not nearly as dramatic as you state.
Before trying your method, I think people should be able to answer YES to these three questions:
- Do you really need the extra speed? (I'll bet most applications don't.)
- Are you willing to give up all other Bridge capabilities to get a faster console?
- Are you willing to disable your only Linux console port that would let you log in and fix problems if you run into Linux issues that prevent network access using SSH?
This is the sketch I used to test the Console speed:
#include <Bridge.h>
#include <Console.h>
void setup() {
Bridge.begin();
Console.begin();
}
void loop() {
while (true) {
if (Console.available()) {
int c = Console.read();
if (c == '~') { // Tilde '~' key pressed for start sampling?
while (Console.read() != -1);
break;
}
}
delay(10);
}
for ( unsigned long i = 0; i <= 4294967295; i++) {
Console.print(i);
Console.print(',');
Console.println(random(1023));
Console.flush();
if (Console.available()) {
int c = Console.read();
if (c == '^') { // '^' key pressed for stop?
break;
}
}
delayMicroseconds(100);
}
}
And this is how I accessed it:
ssh root@ yourYunsName.local 'telnet localhost 6571'
There are no Linux changes required. Can you run that on your setup and post the speed result? That will be the only meaningful comparison.