[SOLVED] Connection closed by foreign host when using two files

I have written some simplified code to represent my problem. When either file is used separately, it works perfectly. However, when I try to utilize both, I have the "Connection closed . . ." error.

I have attached a small file that will throw this error. I am using an Arduino Mega with a YUN shield. I am loving this thing, except for this quirk.

TestReadFile.ino (675 Bytes)

void loop()
{
  String dataString;
  dataString = "Hello World";
  File dataFile = FileSystem.open("/mnt/sda1/logFile.csv",FILE_APPEND);
  dataFile.println(dataString);
  Console.println(dataString);
  dataFile.close();
  char nextPosition;
  File printDataFile = FileSystem.open("/mnt/sda1/print", FILE_READ);
  nextPosition = printDataFile.read();
  Console.println(String(nextPosition));
  printDataFile.close();
  delay(1000);
}

working OK.

Interesting. Possibly a firmware difference? I am using the latest firmware on the Yun shield. I debugged mine bit more. The updated code has some console statements that I used to debug. I managed to get the code to work by adding the time process. I have no idea why this makes any difference. I thought maybe it was the delay. So, I tried to replace it with a delay of 20 seconds. That didn't work. So, I went back to using the time process. Without it, the code would get stuck on the read or println statements, depending on the order of the files.

Does anyone have a clue on this? Why does the time process make a difference?

TestReadFile.ino (933 Bytes)

Check bridge version:

opkg update
opkg info cpu-mcu-bridge
Package: cpu-mcu-bridge
Version: 1.5.1-2
Depends: libc, python-mini
Provides:
Status: install ok installed
Section: utils
Architecture: ar71xx
Maintainer: OpenWrt Developers Team <openwrt-devel@openwrt.org>
MD5Sum: 4db6f7b53e97853f9c80ffbf09bbd5f9
Size: 12839
Filename: cpu-mcu-bridge_1.5.1-2_ar71xx.ipk
Source: feeds/packages/arduino/cpu-mcu-bridge
Description: Bridge lets linux and arduino communicate
Installed-Time: 1415950949

Package: cpu-mcu-bridge
Version: 1.5.1-2
Depends: libc, python-mini
Provides:
Status: install ok installed
Section: utils
Architecture: ar71xx
Maintainer: OpenWrt Developers Team openwrt-devel@openwrt.org
MD5Sum: 4db6f7b53e97853f9c80ffbf09bbd5f9
Size: 12839
Filename: cpu-mcu-bridge_1.5.1-2_ar71xx.ipk
Source: feeds/packages/arduino/cpu-mcu-bridge
Description: Bridge lets linux and arduino communicate
Installed-Time: 1439889610

Unless I am missing something, this looks identical to the one you posted (except for installation time, of course).

Test working fine at

Model: Dragino v2
Version: Dragino-v2 common-2.0.5
Build Tue Jul 21 20:24:45 CST 2015


Upgrade Yún shield's firmware

I am already at the latest Yun firmware:

Model Dragino v2
Firmware Version Dragino-v2 common-2.0.5
Kernel Version 3.3.8

Are you also using an Arduino Mega R3? Mine is the Android version. So, it has the extra USB port to plug in a phone or tablet.

Maybe the issue is with the IDE.
I am running version 1.6.3 on Windows 8. I had to add the "Arduino Mega 2560 -- Yun" to the list of boards. I installed Samba server on the Yun and added two shared folders.

I test at few clone Megas with IDE 1.6.5/Windows 7.

refresh firmware?

cd /tmp/
wget http://www.ibuyopenwrt.com/images/dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin
md5sum  /tmp/dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin
daef7d526145f6e314ea816cae14de5c  /tmp/dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin
kill-bridge
exec sysupgrade -n "/tmp/dragino2-yun-common-v2.0.5-squashfs-sysupgrade.bin"

Reinstall IDE and Dragino profile.

Setup Dragino and Arduino IDE

Amazing! That solved it. It is sooo much faster now when compiling, running, and executing. I believe the IDE was the issue. I am supposedly running the same version that I was running. But, it actually looks a little different. I had installed version 1.6.3 and upgraded to 1.6.5. However, removing and re-installing was the answer. Thank you for assisting me with this. Good job.

Edit the title of thread as "[SOLVED]" please?