read/write values from 3 yun

hello to everyone,

I'm sorry but i don't know if this is the right section of the forum (if not please , admins, forgive me).

I'm not so expert in programming issues so I hope in your help..

i need to read and write from a single webpage values to different arduino yun

the idea is to have 7 nodes (yun boards) connected to my home wifi that turn on or off rleays and read some values from analog pins.

nodes are

1) 192.168.1.77 2) 192.168.1.78 3) 192.168.1.79 4) 192.169.1.80 5) and so on

I can add also a supernode if needed to store the main html page (could be 192.168.1.70);

the questions are....

1) its possible with Ajax to update status from different nodes using a single function???

in the example found into the book of Marco Maganin "alla scoperta di arduino yun" the line was

         server = "/arduino/stato/99";
         richiesta = new XMLHttpRequest();
         richiesta.onreadystatechange = updateasincronoStato;
         richiesta.open("GET", server, true);
         richiesta.send(null);

if i change the address with

server="192.168.1.77/arduino/stato/99"";

running the page onto another arduino yun (192.168.0.70) it can work properly?

if yes I could try to modify the function to accept an ip address as parameter and repeat it with a cicle for-next changing the address;

2)It will be possible to send multiple command (changing accordly the function) to different Nodes?

3) what could be the best and simple way to obtain this result?

thanks in advance to everyone

Livio

Presumably one of the devices is a server.

I would expect the other devices (acting like browsers) would send a request to the server including something to identify themselves. Then the server could send back the correct data.

Or the server could send the all of the data in response to every request and the receiving device could figure out which piece of data is meant for it.

I would do all this stuff on the Linux side of the Yun using Python.

...R

Hi Robin

it’s my fault…the explanation is not clear

I want to open a web page from Supernode (192.168.1.70 arduino yun active as web serever with index.html in /arduino/www folder into sd card)

When the page is opening i need to recive info and status (every x second) from nodes (arduino yun 192.168.1.77 ; .78, .79 and so on) and send command to the same node ( one ore two or all nodes) from the index.html page;

Attached the example from Marco Magnani Book …it’s what i want but i need all the information from different arduino yun with different IP address in a one page…

8330-YUNBOOK1.zip (190 KB)

Using a Yun as a Supernode seems fine, but using a Yun for switching relays on/off and updating via ajax, looks like killing a fly with a bazooka. Arduino UNO + Ethernet shield or a NodeMCU should be enough.

liviomerola: When the page is opening i need to recive info and status (every x second) from nodes (arduino yun 192.168.1.77 ; .78, .79 and so on) and send command to the same node ( one ore two or all nodes) from the index.html page;

There is a lot in what @mart265 has to say.

Another option might be one Yun operating as the server and some Unos with cheap ESP8266 WiFi devices.

However, assuming you want to use Yuns (or at least a WiFi approach) you need to realize that a server cannot initiate communication with a browser (I use the term very loosely to mean everything that talks to the server). The browser must initiate the communication.

You could easily have code in your slave/browser devices so that they contact the server at regular intervals. As part of its "request" the slave/browser can send an identifier.

The process will be exactly the same as if you had a few PCs communicating with another PC operating as a server.

If the project was running on PCs you would probably use cookies to identify the individual slave/browsers but I don't know whether an Uno has the capacity to handle cookies. The Linux side of a Yun could easily do so.

...R

Robin thanks for the answer, but the question is not browser/non browser, server/client

I know that if I want retrieve data from a server I have to send a request and then the server reply to my request.

Assuming that i don’t want to use ESP8266+uno board or a standalone ESB826 (I believe that is possible but I have not checked and I’m not sure about this) the start request will arrive from a smatphone or a pc or something else with a browser calling the page index.HTML that is on the yun server (SUPERNODE), at this point yun supernode have to ask to other yun boards (nodes) the value of it’s pin.

assuming that i have this yun boards
0) 192.168.1.70 (SUPERNODE)

  1. 192.168.1.77 (node)
  2. 192.168.1.78 (node)
  3. 192.168.1.79 (node)
  4. 192.169.1.80 (node)
  5. and so on (node)

the flow it’s the following:

  1. user open phone or pc browser opening http://192.168.1.70/myfolder/www/index.html
  2. index html have to request (via ajax/REST/Bridge library) the values of each pin of each nodes
  3. each nodes will reply status or value for all the pins
  4. retrieve all status or values in a index html page
  5. update the staus or values every x second in the index.html page while the page is open
    ) if user modify the staus of one or more pin the page index.html have to send the command to the right node/pin

in the zip folder I attached in the previuos message there is the example for only one arduino yun…

window.onload=CaricaStatoPin; function CaricaStatoPin(){ leggiStato(); } function leggiStato(){ setTimeout(leggiStato, 2000); document.getElementById("descrizione").innerHTML = "--- Attendi ... ---"; server = "/arduino/stato/99"; richiesta = new XMLHttpRequest(); richiesta.onreadystatechange = updateasincronoStato; richiesta.open("GET", server, true); richiesta.send(null); } if i change the function as follow ( i know this is not enough but is only to explain the concept): function leggiStato(IPNODE){ setTimeout(leggiStato, 2000); document.getElementById("descrizione").innerHTML = "--- Attendi ... ---"; server = IPNODE & "/arduino/stato/99"; richiesta = new XMLHttpRequest(); richiesta.onreadystatechange = updateasincronoStato; richiesta.open("GET", server, true); richiesta.send(null); } this may work? I will call the function in a for-next cicle passing to the function the ip of each nodes to get all the values

mart256: Using a Yun as a Supernode seems fine, but using a Yun for switching relays on/off and updating via ajax, looks like killing a fly with a bazooka. Arduino UNO + Ethernet shield or a NodeMCU should be enough.

Mart not only relay but also sensors... :-)

and a "must have" is the possibility to enter use linux for each node;

arduino uno + ethernet is not possible due to cables

ESP8266 have not linux on board (I don't know if there is the possibility to load linux or other system on it, but if there is the possibility I'm not able to do it :-) )

mart256: but using a Yun for switching relays on/off and updating via ajax, looks like killing a fly with a bazooka.

why not? :-) so the system is ready for new implementation....think about dna mutation...what's app if the fly will transform in a BIIIIIIIIIGGGGG fly???

your spray will not kill it ...my bazooka yes :-P

jokes apart ...think about of a breackage of unique arduino yun...

your system will not work.. my system can switch from one node to another just writing a different IP into smartphone browser (yes i know I have to put in all arduino yun the index.html page with the correct IP nodes...but it's only initial setting)

Try the MQTT protocol, its made for the Internet of things (IOT). Yep, nodemcu (esp8266) can run standalone, can read sensors and is capable of running MQTT tasks. Your supernode can run a mqtt broker on e linux side.

Im not trying to be rude, just trying to save you money (how gentle am I). Esp8266 is 4 USD, Yun is 70 usd.

MQTT Broker at Yun

liviomerola: at this point yun supernode have to ask to other yun boards (nodes) the value of it's pin.

To the best of my knowledge that is not possible IF the server is connected to the other yun boards using WiFi.

You need a system in which the other boards have already sent their data to the server so that it already has the data when the request comes from the phone (or wherever).

...R

Extended bridge class into super bridge class, access it from internet.

bridge class only allow localhost access.

http://forum.arduino.cc/index.php?topic=323690.msg2243510#msg2243510

http://forum.arduino.cc/index.php?topic=323690.msg2243520#msg2243520

liviomerola:
hello to everyone,
::::SNIP::::
2)It will be possible to send multiple command (changing accordly the function) to different Nodes?

  1. what could be the best and simple way to obtain this result?

thanks in advance to everyone

Livio

WOW, Livio, I’ve read all the responses. If I might, I will change the story a bit.

#1 the plan - as you layed out - will work, but has lots issues to be overcome.
#2 Your biggest problem is CORS. To overcome CORS you need control of the server and the client (browser or phone)
#3 I work with mobile and tell you - you have a similar problem. We are required (in Phonegap) to use “white-lists” for servers.
#4 You can have a Supernode or Master server, which ever you want.

So, you can have one webpage that connects to multiple servers and the browser (phone) can receive each individually.

Do you have a question?
Jesse

jessemonroy650: So, you can have one webpage that connects to multiple servers and the browser (phone) can receive each individually.

I don't understand this.

Where would the "one webpage" exist ? Where would the "multiple servers" exist and what would each of them be for ?

It sounds like a lot of work to get the browser to go to several servers if it could get all the data from a single server - I am (of course) assuming a human-activated browser on the phone.

I have not read your CORS link in any detail but my immediate reaction is that the OP can find a solution without needing to deal with that.

...R

Robin2: I don't understand this.

1) Where would the "one webpage" exist ? 2) Where would the "multiple servers" exist and what would each of them be for ?

3) It sounds like a lot of work to get the browser to go to several servers if it could get all the data from a single server - I am (of course) assuming a human-activated browser on the phone.

4) I have not read your CORS link in any detail but my immediate reaction is that the OP can find a solution without needing to deal with that.

...R

@Robin2

On #1, the "one webpage" could exist on a master server, or supernode (as Livio suggests). On #2, I assume "multiple servers" would sit in a common environment - like in the same room , or the same yard, or the same warehouse. On #3, I agree, but I am offering solutions. I don't have enough information to suggest otherwise. On #4, I do NOT blame you for NOT reading CORS. It is long, tedious, winding. However, the CORS issues is something every webApp (webserver-based apps) and mobileApp (mobile-device-based) developer runs into.

On CORS, the issue it deals with is compromised websites. In the classic problem, someone breaks into a website and plants weblinks (or webpages) that redirect or link to evil websites. CORS deals with this issue by NOT allowing a webpage, by default, to access any resources or pages other than those from the same domain. This is known as "same origin policy". This policy is incorporated into all modern webbrowser.

There are three ways to deals with CORS.

1) Override the setting in the webbrowser. This is option is hidden on most browsers and is not recommended. Mostly because it is an all or nothing option.

2) Write a custom App, that deals with this issue at the socket level. This is because the browser enforces the issue. You basically write your own browser.

3) Follow the CORS policy. With CORS the server needs to respond in the HTTP protocol layer with Access-Control-Allow-Origin: *

However, the problem with #3 is that it is not trivial to add an extra HTTP (header) response.

And on #2, you can write a Mobile-App to get around it. But you need to learn how to write mobile apps first. Boilerplates are available, so getting it operational is easy, but maintenance can be a difficult.

So, as has been stated, this is not trivial.

Jesse

jessemonroy650: So, as has been stated, this is not trivial.

Thanks for all that Jesse, much appreciated.

I agree with you about not-trivial.

That is why I suggested what I believe is a perfectly workable solution where each "slave" keeps the server updated with its data by making a request (Post) to the server that contains the slave's data. Then at any moment the server can send the latest data in response to a request from the browser on the phone.

It is probably not quite how the OP envisaged the system but it is simple and none of the CORS security issues is being challenged.

...R