Mounting NAS on Yun after restart

Bought a NetAtmo in a budget careless period, but dislike the fact that you need a smartphone or tablet around to consult the outdoor temperature. So thought of making a display showing the kids how warm it is so they know what clothes to wear in the morning…

Idea I had: running a PHP-script every 15min on my NAS (Synology) fetching measurements via an API from the NetAtmo server, and generating a text-file containing some of the measurements. Then, on a frequent basis, I would copy that text-file over to my Yun, and display it on an lcd.

Got it to work after a while, but when i unpower and restart the Yun, the necessary mounting of the NAS-drive and copying of the text-file does not work properly

Below the script I’ve written (I’ve been stealing 90% of this coding, and my Linux skills are poor…)


// **********************

// Bridge for reading with SD-card an running shell-commands
#include <Bridge.h>
#include <FileIO.h>
#include <Process.h>

// LiquidCrystal_I2C library for display to LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

Process p;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

// **********************
// **********************

void setup() {
Bridge.begin();
FileSystem.begin();
lcd.begin(16,2);

// mounting the NAS-folder
p.runShellCommand("/mnt/sda1/mount.sh");
}

// **********************
// **********************

void loop() {

lcd.clear();
lcd.setCursor(0,0);
lcd.print("…updating…");

// copying over the data-file
p.runShellCommand("/mnt/sda1/copy.sh");
File f = FileSystem.open("/mnt/sda1/out.txt", FILE_READ);

// reading the file bit-by-bit
String output = “”;
while (f.available()) {
output += (char)f.read();
}
f.close();

int sepnum = 0;
int seppos[7];
seppos[0]=output.indexOf(‘n’,1);
seppos[1]=output.indexOf(‘n’,seppos[0]+1);
seppos[2]=output.indexOf(‘n’,seppos[1]+1);
seppos[3]=output.indexOf(‘n’,seppos[2]+1);
seppos[4]=output.indexOf(‘n’,seppos[3]+1);
seppos[5]=output.indexOf(‘n’,seppos[4]+1);
seppos[6]=output.indexOf(’[’,seppos[5]+1);

String tempbinnen = output.substring(1,seppos[0]);
//String co2binnen = output.substring(seppos[0]+1,seppos[1]);
String humbinnen = output.substring(seppos[1]+1,seppos[2]);
//String drukbuiten = output.substring(seppos[2]+1,seppos[3]);
//String dbbinnen = output.substring(seppos[3]+1,seppos[4]);
String tempbuiten = output.substring(seppos[4]+1,seppos[5]);
String humbuiten = output.substring(seppos[5]+1,seppos[6]);

lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Ti=”+tempbinnen+“C Hi=”+humbinnen+"%");
lcd.setCursor(0,1);
lcd.print(“Te=”+tempbuiten+“C He=”+humbuiten+"%");

//Serial.println("Ti= "+tempbinnen);
//Serial.println("CO2i= "+co2binnen);
//Serial.println("HUMi= "+humbinnen);
//Serial.println("PRESe= "+drukbuiten);
//Serial.println("DBi= "+dbbinnen);
//Serial.println("Te= "+tempbuiten);
//Serial.println(“HUMe= “+humbuiten);
//Serial.println(””);

delay(60000);
}


The mount.sh script:
mount.cifs //192.168.0.192/web/mnt/nas -o user=xxxx, pass=xxx sec=ntlm

I don't have an answer why the NAS folder doesn't mount, but I do have a question: why involve the NAS at all? Why not have the Yun make the API requests directly to the device to get the information? (Note, I know nothing about the API, but odds are you should be able to call it from the Yun?)

You're right probably that would work as well. But this way the results could be picked up by multiple applications, and i planned to do datalogging in a MySQL DB on the NAS.

That said, I have to list the details of all shell-scripts (mount nas, copy file) as soon as I'm home. I was jumping to conclusions when stating the mounting of the NAS doesn't work. Reading the code again not sure the path to the SD-card is correct when not explicitly mounting it.

= [Q:] I cannot connect to My Arduino Yún. What do I do? =

First it's good to know, when Arduino Yun cannot find the AP you have set it for (like your home wifi), it has a script that puts it back into default SSID and AP mode.

Next, you may have already watched this video, but it's worth watching again. Pay extra attention to the part with the sketches. Getting started with Arduino Yún - tutorial (6:53) https://www.youtube.com/watch?v=9-hPhWHWnvs

Then, read the short instructions immediately below. We (the volunteer support group) already know these steps by heart, so be familiar with the different reboot methods, and especially the 30+ second wifi reset. Also, not mentioned on that page, if you reset the Wifi/Linux part of the Yun, it will take from 2-8 minutes for the reboot. Lastly on this part, YOU MUST WAIT for the Linux portion to fully boot BEFORE YOU PRESS ANY of the RESET buttons.

Resetting the processors (AR9331, WiFi, and 32U4) http://arduino.cc/en/Guide/ArduinoYun#toc6

Then start over, plug your Yun into the USB port, run this sketch, and hit the ''Wifi Reset button'' (for 5-10 seconds). (see attached image) http://arduino.cc/en/Tutorial/YunSerialTerminal

The YunSerialTerminal provides a simplified console access to the Linux part of the Yun. It works via the USB port (the one that powers the Yun - the microUSB). From there you'll be able to run a few commands to give us a better idea of problems.

Also, be ready with this sketch YunWiFiStatus. This sketch will help us see the status of your home AP. The sketch prints the wifi status to the console every 5 seconds or so. This sketch might seem familiar as it was in that first video link (above).

Let us know how it goes. Post results from the YunSerialTerminal, if you are still having problems. Please use markup when posting results. (see attached image)

Jesse

Dear,

Thanks for the elaborated answer. I do succeed in connecting to my YUN, both via USB and Wifi. Let me know if you think still above would be necessary...

My sketch worked fine couple of times, but that might be due to the fact that I had been playing around with mounting file systems manually via ssh.

If I connect via putty and 'nano' the out.txt file in /mnt/sda1 it does contain text, f.e. [20.1n549n53n1011.6n37n11.5n73[

Makes me think the issue is somewhere with mounting/reading the SD-card. My Linux skills are poor as a matter a fact.

below the content of the shell scripts I use:

mount.sh= mount.cifs //192.168.0.192/web /mnt/nas -o user=admin,pass=HIDDEN sec=ntml

copy.sh= cp /mnt/nas/out.txt /mnt/sda1/out.txt

Kind regards, Stijn

@Stijn, in review of you comments, let me add the following information.

YunOS is based on LinioOS, which is based on OpenWRT. Detail here: The Yún CLI Tools

If you google: mount.cifs openwrt, the following link show up near the top.

OpenWrt.org CIFS Client

It appears this tool is a bit convoluted and complex.

On your question in the reply, yes using an intermediate (NAS) server is a bit complex. Using a NAS server is generally considered okay for light to medium duty work. However, intermediate servers are generally not used because they tend to become unreliable over time. The less moving parts the better. Most organizations I know use these servers to solve political issues - not technical issues.

If however, you are doing this as a learning experience or because you got extra equipment handy - go ahead. Just be aware it adds complexity.

Best of Luck Jesse

Thanks for all replies.. Yes mainly learning experience, appears most of the time my family members are not exactly waiting for my creations :)

Got it to work in the mean time by the way, properly restarting the WLAN and afterwards the 32U4 did the trick!

So better subject for this thread would have been 'mounting NAS on Yun after re-powering'..

Many thanks!

Stijn

@Stijn Excellent!!! We will make a note for that

"'mount (..) NAS on Yun after re-powering' and properly restarting Yun".

As such, this guide will also help you:

Getting Started with the Arduino Yún

Yun Hardware Guide See: Automatic (Software) Reset and Bootloader Initiation

Best of Luck Jesse