Websocket control of arduino

Discussion in 'General Programming Discussion' started by SepiD, Mar 10, 2014.

  1. SepiD

    SepiD New Member

    Joined:
    Mar 10, 2014
    Messages:
    6
    Likes Received:
    0
    Hello, I want to make a webserver hosted on udoo through which I could execute scripts on arduino side (some simple io and PWM), so far i found a tutorial of the remote web station which does exact opposite - reads on arduino and passes it to the server but it doesn't help me much since it doesn't explain how exactly that works so i can't apply it. I am looking for suggestions how could it be done most efficiently.
     
  2. francescomm

    francescomm Member

    Joined:
    Dec 14, 2013
    Messages:
    80
    Likes Received:
    4
    It mostly depends on your preferred language/server, PHP, Python, Javascript, C++ with Apache/Node/..

    If you can write "get a A0" to a serial port (to get analog value of pin A0) or "set a 10 512" (to set PWM value of pin 10 to 512) with any script, and wait for a response, you may use this:

    https://github.com/francescom/Pilot.ino

    It does compile on the UDOO (no need for external computer) and you can test from Serial Monitor (just type serial commands to dim leds)
    If you know PHP, you can install it and there is a PHP class/library for it. If you know Python there is some sample code here on the forum (and I'm writing a class for it).

    Also there is a JSON-RPC server for the Arduino from another user, a few posts below yours, that allows remote method invocation on the Arduino from the UDOO.

    If you know Javascript/Node you can install Node on the UDOO but you either have to interface with Pilot.ino via serial or JSON-RPC or write your own Arduino sketch (you can start from Pilot.ino code, of course) as the nice node-udoo library does not support PWM or Analog yet.
     
  3. SepiD

    SepiD New Member

    Joined:
    Mar 10, 2014
    Messages:
    6
    Likes Received:
    0
    Wow, Francesco, thanks for such extensive reply!
    I'd rather do a php server. Pilot.ino looks beautiful. Which way do you think would be more stable/simpler and maybe efficient?
     
  4. francescomm

    francescomm Member

    Joined:
    Dec 14, 2013
    Messages:
    80
    Likes Received:
    4
    Then this:

    http://www.udoo.org/ProjectsAndTutorial ... eb-server/

    will install PHP, Apache and Mysql on the UDOO (I did the "simple way" and worked fine).

    After that you can either run a PHP web page that talks to the Arduino with Pilot.ino (just include the pilotino.php library and follow the examples) or, as the sample on github shows, a command line PHP shell script that loops forever and reads sensor data (you may save it to Mysql or upload it to an external website). It probably depends on what you need (light led on click of a button or write room temperature data to a website)..

    Most of the files in the PHP folder are examples of usage:

    - wait for a pushbutton then launch script
    - light leds (like a chrismas tree)
    - send data to remote server (and there is a receiving PHP script also)
     
  5. Rickor

    Rickor New Member

    Joined:
    Nov 30, 2013
    Messages:
    9
    Likes Received:
    1

Share This Page