Hi,I'm new to Arduino, what I'm saying here is very likely to be wrong.
Just want to share some notes,
Do correct me if my understanding is wrong .
The first thing I wanted to do when I have an Arduino Yun was to make it connected with the web, the internet of things.
So far I have found several ways that allow Arduino Yun to connect with the world.
- Build API with Yun's native Bridge library YunServer and YunClient
This simple code basically builds up a server on Arduino provides a set of APIs. Other devices on the same internal network can call these API to access the features on Arduino.
It's suitable for getting a few data from Yun, but not for more complex data processing.
And you also need to make Yun accessible from the web, if you really want run the Arduino standalone.
- Use Yun's native Bridge HttpClient get method
Libraryhttp://arduino.cc/en/Tutorial/HttpClient
the HttpClient get method allows you to call a GET api.
However, for some reason, it doesn't include a POST method.
But I found out you can use http POST by using Bridge's linux CURL command.
- Follow Arduino instructions, use Temboo
Maybe I missed something, it seems only give you a limited number of features.
- Use serialport / Johnny-Five packages
They are cool, and I'm sure they can do more, but the concept of these packages is essentially to establish a port connection with Arduino, without further tweaking, with another computer, which seems against the concept of Arduino Yun ( to be something standalone ).
I haven't come this far, but could it establish the connection remotely, ideally one server to multiple devices ?
- Build a Nodejs server on Arduino Yun
Here is a good article.
http://www.tigoe.com/pcomp/code/arduinowiring/1216/
I haven't really tried, just a bit worried about Arduino's capacity.
After reviewed all these solutions, I'm relatively in favour of the 2nd method- Use Yun's native Bridge HttpClient get method. I was wondering, why not just simply make http calls from Yun ?
The rationale is:
-
Arduino Yun can stand alone, all you need is a power supply.
-
You don't need to expose Yun to the internet by building a server on it.
-
Arduino language is low-level, all it needs to do is to make http calls and deal with what it's born to do.
-
You can have a nodejs server, in the cloud which deal with more complex processing, i.e. exchange data with the database.
-
It's cross-platform.
So I made this simple experiment,
it's constitute by three parts:
-
an Arduino client ( makes http GET/POST calls, and deal with the electronic part.)
-
a Nodejs server ( provides API )
-
a web/mobile client by angularjs
a demo: - YouTube
Make http GET call:
client.get("http://192.168.1.70:3000/getSignal");
here my internal ip for the nodejs server was 192.168.1.70, but it could be anything like example.com.
Make http POST call:
shell.runShellCommand("curl --data"number="+String(pitch*100)+""http://192.168.1.70:3000/postSignal");
Get response:
while (client.available()) {
String command = client.readStringUntil('/');
Serial.println( command.toFloat()(sensorValue/1000));
tone(toner, command.toInt()(sensorValue/1000), speed);
}
A noticeable point is you can use stream class methods to read the stream which GET/POST method come back with.
One of the drawbacks here is clearly this program makes too many GET calls.
This is my idea so far.
Again, I'm not experienced in Arduino at all. I don't know which way is more efficient and useful.