1 2 Previous Next 24 Replies Latest reply on Oct 11, 2015 9:06 PM by Frederick Blais

    Webpage to arduino ide communication

    Krolo

      I want to be able to run different functions of the arduino based on web page input.

      I'm fairly good at php, arduino ide, as well as working my way around linux and basic shell scripts. My idea is to install apache/php to be able to write or modify a shell script and then execute it which will run the commands to toggle a pin on the arduino. That should work ok unless I want to send more than a bit of information. Ideally I want to send a byte command to the arduino to tell it what to do.

       

      Unfortunately I do not know c/c++, js, or python.

       

      Is there an easy way to pass a byte of information to arduino from a shell script?

       

      Am I better off trying to learn js or python?

      After a bit more searching JS seems to be the way to go. Should I get a JavaScript book and just flip to page 1 and go from there, or is there some fast track reading I can do specifically for the edison development?

        • 1. Re: Webpage to arduino ide communication
          Intel_Alvarado

          Hi Krolo,

           

          I believe that the easiest way to get your application running is by using JavaScript. Take a look at this link http://www.tutorialspoint.com/javascript/ , it has some links to let you have a quick start using JavaScript.

          Also, take a look at https://github.com/tkambler/edison.js/ it has some information that you might find useful.

           

          Regards

          Sergio

          1 of 1 people found this helpful
          • 2. Re: Webpage to arduino ide communication
            CMata_Intel

            Hi Krolo

             

            Do you still have questions about this? Have you had any updates in this?

             

            Regards;

            CMata

            • 3. Re: Webpage to arduino ide communication
              Krolo

              Reviewing objects for java script helped me a little. I have an javascript example code to write a value over serial communication that is running in node. I have a basic arduino sketch to read the serial data and then display it but it does not seem to be getting any data. The javascript code is writting to /dev/MFD1 but it does not seem to work. If I switch it to /dev/MFD2 I see it outputting to the serial monitor but it seems to bypass the arduino though.

               

              I have working javascript to write data in spi and i2c, but I have yet to find a simple working example to read that data and put it into a string on the arduino side.

               

              I really just want a simple way to have a drop down field in a webpage to change a variable. on click or update pass that variable to arduino ide and have it preform a new function based off the simple variable. I think the serial would be the easist way but I'm using the example serialevent sketch with no luck.

              • 4. Re: Webpage to arduino ide communication
                Frederick Blais

                Hey Krolo,

                 

                I would like to help you with that. I have not installed Arduino IDE yet but I will do it tonight. There must be a way to interact with the command line with the an Arduino sketch on the Edison. According to here : Galileo Getting Started Guide - learn.sparkfun.com they are able to use the "system" function to do it on the Galileo. It should be the same with the Edison. Also there must be a way to open a file on the Linux filesystem.

                 

                Here is what I have in mind:

                1. Get Python's Flask web microframework on your Edison (install it with pip)
                2. Make a simple html page with a form that accepts a couple values
                3. put this data in a named pipe (using os.mkfifo) in JSON format.
                4. Read from this pipe in the Arduino sketch

                 

                This may look complicated, but it's really simple. I'm sure I can do this in under 30 minutes.

                 

                Can anyone confirm that you can read/write a file in the Linux filesystem from an Arduino sketch?

                 

                 

                some links:

                Python os.mkfifo() Method

                Introduction to Named Pipes | Linux Journal

                bblanchon/ArduinoJson · GitHub

                Quickstart — Flask Documentation (0.10)

                Edison - Software Downloads

                • 5. Re: Webpage to arduino ide communication
                  Frederick Blais

                  Krolo

                   

                  I managed to get it to work. Take a look at this screenshot :

                  screen1.png

                   

                   

                  Linux/Python side :

                  As I said in my last post, I made a Python script that instantiate a Flask web server. This web server serve a simple index.html file that contains a jQuery mobile slider Slider - jQuery Mobile Demos

                  I made a callback that when the value of the slider change, it is sent by Ajax back to the Python script.

                  Back in the python script, I receive the data and push it in a Linux named pipe. (this pipe is created in /tmp/ directory)

                   

                  Arduino side:

                  In setup, I open the named pipe. I read from it continually and display the result in the serial terminal.

                  It is really nice that the sketch can mess with the Linux filesystem.

                   

                  Just tell me if you are still interested by this. I will clean my code a little bit before sharing it.

                   

                  The webpage could have a lot more stuff in it, like buttons, checkbox, radio buttons...

                  Something nice would be to send the data as JSON and receive it as JSON on the Arduino sketch too. The way it works now is just writing numbers in the fifo.

                  • 6. Re: Webpage to arduino ide communication
                    Frederick Blais

                    Okay, I've got something clean now

                    Dropbox - ArduinoWebControl

                     

                    Here what it looks like on my iPhone. Clicking on the toggle switch turn the on-board LED on/off.

                    IMG_1356.PNG

                    • 7. Re: Webpage to arduino ide communication
                      Ewgor

                      Hy,

                      Could you please help me with all needed info to understand how can i make a webpage that can be accessed with an ip and so to create a few flip switchesi and a few sliders with my arduino board through jquery libraries?

                      Do i need to have a server running 24 hours a day for that scope?

                      I'm trying to make something like this for more than 4 mounths by now and what i manager to do was only to test different sketches posted by others but i couldn't realize how do i need to match the Java, Ajax, jquery, c# or PHP, all this softwares are way beyound me!

                      So, what i need is to get some help, step by step, starting with only one led and a simple flipswitch that can be operated via ethernet! After that, everithing can be developed.

                      Thanks.

                      • 8. Re: Webpage to arduino ide communication
                        Ewgor

                        Bellow you can see the web page that i create in HTML and calling the j Query online libraries. the bad thing is that i tried alot of possibilities to make work with arduino board but no positive result by now ...

                        Below is my beautiful web page

                        IMG_2126.PNG

                        • 9. Re: Webpage to arduino ide communication
                          Frederick Blais

                          Ewgor,,

                           

                          do you have an Edison or it is for a regular Arduino? I see you are talking about Ethernet. The Edison have no Ethernet ports. And as far as I know the Edison was not on the market 4 months ago.

                           

                          Fred

                          • 10. Re: Webpage to arduino ide communication
                            Ewgor

                            I dont have an Edison (whats that? ), all i have is an Arduino Mega (Uno too) with an Ethernet shield, a connection to LAN via an router TPLink and that's all.

                            • 11. Re: Webpage to arduino ide communication
                              Frederick Blais

                              You are on the wrong forum then, this forum is about the Intel Edison that has built-in WiFi and Bluetooth.

                              Try this forum : Programming Questions

                              or buy an Intel® Edison and Arduino Breakout Kit - DEV-13097 - SparkFun Electronics   

                              • 12. Re: Webpage to arduino ide communication
                                Ewgor

                                Sorry for that, i read the initial post and i thought that here i can get some help ... Anyhow, thanks for the links you posted, i'll try to get some help out here.

                                All the best.

                                • 13. Re: Webpage to arduino ide communication
                                  Krolo

                                  So your using

                                  $.getJSON('/_update', data);

                                   

                                  to send the data to a temp file. Then your using python to pipe it? Is the python script run once or is it continually running? Can it be done without the pipe for less than real time effect?

                                   

                                  I am looking to do pretty much this except I was trying to do it over serial communication. Do we need to pipe serial communication between linux and arduino before it will work as well?

                                  • 14. Re: Webpage to arduino ide communication
                                    Frederick Blais

                                    $.getJSON('/_update', data);   is an Ajax request.

                                    this is used to get the data of the html widgets and send them to the flask webserver using the HTTP GET method with the data encoded in the URL.

                                    From inside Python, I forward this data to the pipe (also known as FIFO). This is what you see below :


                                        data = json.dumps(request.args)

                                        print data

                                        fifo = open(FIFO_PATH, "w")

                                        fifo.write(data)

                                        fifo.close()



                                    You can use Ajax to send the data in real time (when the value of the form changes) or you can use a submit button that you have to press each time you want to send the GET request to the webserver. I prefer the realtime solution.

                                     

                                     

                                    Is the python script run once or is it continually running?

                                     

                                    It is continually running because you need the webserver to run in the background and allow it to pipe the data to the Arduino

                                     

                                    Can it be done without the pipe for less than real time effect?

                                    Writing to a file from Python and reading from it from the Arduino is the only way I can think of to do this. Search on Google for Linux Interprocess Communications.

                                    The advantage of the pipe over a regular file is that the data does not have to be stored, all we want to do is to put the data in the file and retrieve it on the other end. This consumes a minimal amount of memory.

                                     

                                    I am looking to do pretty much this except I was trying to do it over serial communication. Do we need to pipe serial communication between linux and arduino before it will work as well?

                                    I assume that you wanted to do a loopback (wiring TX to RX of the serial port). I'm not sure that this would have worked because 2 Linux processes cannot have the same serial port open at the same time. In my opinion, it is much better to find a software solution than an hardware solution.

                                     

                                    try it! I'm sure you'll like the way it's working. I'm always there to help if you need so.

                                     

                                    Fred

                                    1 2 Previous Next