arduino yun bridge
168.0.0 and the yun here is Steve’s Yong. Okay, so if we just go back to previously, we had these these PHP scripts. Now the script that we’re going to use now is this one: insert young IOT, Jason rest data, so let’s just have a quick look at that: insert IOT json rest data, one so we’ll, just edit that in nope into NetBeans now I’m just going to change the Username to too young and the Young’s password is password one and the database we’re using is Steve’s. You know 80 DB, so basically, how this code is going to work is first of all, it’s going to create a connection and it’s going to connect using the server name, which is localhost the username Yann the password and to the database Steve’s young IOT DB. And if it’s an issue with the connection, then the it will die and it will print out an error and connection error. But assuming all is good. What we’re going to do is we’re going to set up an array for a response array. But what we’re going to do is we’re going to go to the to the file. The file get contents PHP input. Now. What that does is that gets the the input post data which comes to this PHP script and it’ll then pass it to this function called JSON decode, which will then decode the post data as a JSON as JSON data and return it into an array which we’re Calling dollar Jason so or an object which is dollar Jason now now what we’re going to do here is see if this dollar Jason is not equal to null, in other words, there’s JSON data has been received by the PHP post and, if so, we’re going to We’Re going to grab the elements of that data in jason, from jason format and put those into into variables, so we’re going to grab the the young, which is we’re going to call that the device, so that will become our device we’re going to grab the the D1 field of the json data and we’re going to put that into a variable called digital one and we’re, going to grab the a zero field of the json data and we’re going to put that into a variable called analog 0.
Now, what we’re going to do is going to use these variables to construct a sequel, insert query for my sequel database, so we’re going to say insert into the under table we’re going to insert the young name, the digital input and the analog input and the values We’Re going to use are dollar device, in other words the yun that we’re using dollar digital one, which is the digital one, data that we received from the json data and dollar analog 0, which is the analog 0 channel data that we’ve received from the from the Adjacent call so then we’re going to run my sequel. I query so we’re going to run the query against the against the connection, so against our connection and we’re, going to run the sequel command and if it’s successful, then we’re going to return a response code of 1 and a response message to say successfully stored and We’Re going to echo that in json encoded format, so the response is going to be encoded into JSON format. If there was an issue – in other words the the query couldn’t be completed, then we get to these elves and we’re going to respond with the code equals two and we’re going to the message will be the my sequel. I error their received and will also encode that as JSON now, if we had no json data, in other words, this all happened. If all of this happened, if the the jason data was available, if there was no json data, in other words else down here, we’ll just echo json data error and then finally, we’ll close, will close the close the connection and free up all of the resources.
The JSON decode there’s, just a little bit of extra coding in here in this JSON decode function, which, if there’s an issue with magic, quotes, it’ll deal with it and it strips the slashes off the string and then returns the JSON decoded string back to here. So that’s the JSON decode that happens there. Okay, so that’s our code. So the way this code is used is this code. Is this PHP code is called from am from from a yun script? Sorry a young sketch. So what we’re going to do is we’re going to bring up that sketch, and this is the sketch here. Ok, so i run through this fairly quickly. This is the sketch we’re going to include bridges, eye height, so we’re going to use the arduino bridge and specifically the yun client on the bridge. So we’ve got our server. Now before, when we looked at the the arduino, we saw that the arduino young to dress was to 17.6 one ninety, two dot, one, six, eight dot, two one, seven dot c. The server address is the address of the the lamp server. So what we need to do is we need to run in ipconfig all and find the IP address of the webserver. The IP address of the webserver is 192.168.1 7.3. Okay, so let’s make that two 17.3 that’s our web server address 192.168.1.1 name. Is yun data we’re going to create an instance of a Yun client we’re, going to set up a character buffer 64 characters and send request is what’s doing the work there’s a separate video that goes through this in a lot more detail, so I’ll just breeze through This, but basically what we’ve got is we’ve got an ADC value, which is an integer value between 1, 0 and 1024.
So we’re going to say, if client connect so we’re going to use the yun, client and we’re going to use client connect and we’re going to. Ah, sorry, if client connect server on port 80, so we want to connect to two 17.3 on port 80, which is our lamp server, and what we want to do, then, is we want to create a post data to yun rest insert Jung, IOT Jason rest data, One PHP so let’s just have a quick look and check if that’s correct, so we’ve got insert Jung, IOT JSON, rest data, 1, dot, PHP and that’s in Yun rest. The unrest subfolder so Yun rest insert Jung, IOT, Jason, rest data, 1, dot, PHP yep. That looks all good, then we’re, going to specify the host, which is our server content type jason. Then we’re going to format into into a buffer of this character, buffer 64 character, buffer we’re, going to format using s printf the json call. So this is our jason and we’re going to say: yong. The yun is Steve’s young digital one we’ll just give it a value of 0, because we’re just testing analog 0. What we’re going to use percent D to specify the ADC value of the analog 0? Then we provide the content length and to get the content length. We’Ll use string length of the buffer, in other words, how how many characters are in this buffer, get the string, length, output that to the client and then a print line, then we’ll print the buffer.
As the request body, in other words the Jason Post data and then we’re done, okay, so we’ll just compile this filing is good. Okay, so we’ll upload the sketch. Now the thing to notice about this sketch is that it does use serial dot print line. To tell us what’s going on so what we can do is we can follow the sketch since I’m doing a yarn on com3 we’ll just check gum. I just didn’t check that, but port comm three, I do na young yep that’s on comm three that’s good, so I’ll just run the serial monitor, and here we see some data coming up. So this is looking good and we’ve got a response: HTTP. 1.1. 200. Okay, so this is telling me it’s sending data 344 is our analog to digital value, with a host is 192 168 to 173 content type application, JSON content length is 51 here’s, our JSON data, and when we get a response of HTTP, 1.1 200. Okay, we know things are just doing just fine, so it looks like it’s working quite well, so let’s just skip over and look at these values. So we’ve got 344 344. So if we go and then go back to here and go back to our display y’know a t table data, we should see some 344 and we do so.
arduino yun bridge Video
arduino yun bridge news
Posted on Tuesday July 03, 2018DevBoard Watch: Say hello to Arduino Yun Rev 2 Electronics Weekly … Continue Reading »
Posted on Tuesday July 03, 2018Arduino Yun bounces back to life with a Rev 2 LinuxGizmos.com … Continue Reading »
Posted on Tuesday February 24, 2015Is The Arduino Yun Open Hardware? Hackaday … Continue Reading »
arduino yun bridge Social
🗓️ Thursday, October 10th
🕓 4pm CET
Originally posted 2015-10-21 13:21:52.