YunIO allows your Arduino Yun or Yun Shielded Arduino to dynamically (1) configure I/O pins, (2) command output pins, and (3) receive input pin updates, via simple web APIs. With such interface, virtually any language can be used to program the Arduino. There is one catch, this is not suitable for time critical tasks that require instantaneous response as the TCP/IP communication comes with latency.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
They are the hardware and software prerequisites:
- Arduino Yun or Yun Shielded Arduino
- Arduino IDE
This is the step-by-step process to get it working:
1. Upload yunio.io into your Yun or Yun Shielded Arduino
2. Edit ServerComm.py; update the URL variable with the actual endpoint that you would like your Arduino to push the I/O values to
3. Upload ServerComm.py onto the Linino side
4. Execute the ServerComm.py (preferablly with Cron so the process won't die when the ssh session is closed)
This will explain how to use the API.
An Arduino pin can be configured to 4 different types: Analog Input (AI), Analog Output (AO), Digital Input (DI), Digital Output (DO). Please note that NOT ALL PINS ARE CREATED EQUAL, so check Arduino sepcifications to see if the certain pin number can indeed achieve the intended state.
Pin Type Code:
AI - 0
AO - 1
DI - 2
DO - 3
Use GET request to configure a pin, the URL should be constructed as follow:
URL Path:
1st digit "C" stands for Configure mode
2nd digit specifies the pin number plus a constant 48 in ASCII (ie. pin 12 is '<')
3rd-5th digits specify the pin type code
Example: configure pin 12 to DO
http://[arduino_ip_address]:9898/C<003
Use GET request to command a pin, the URL should be constructed as follow:
URL Path:
1st digit "A" stands for Action mode
2nd digit specifies the pin number plus a constant 48 in ASCII (ie. pin 12 is '<')
3rd-5th digits specify value the pin should output (ie. 0 - 255). Please note that any value >255 will overflow.
Example: configure pin 12 to output high
http://[arduino_ip_address]:9898/A<001
Any change of value of any pin will trigger an update sent to a server. The update is sent as a JSON string to the endpoint URL specified during step 2 of the Installation. The JSON string has pin number as the key and pin state/value as the value.
Make sure to always parse the value by comma separation as there could be more than one value returned by a pin. The "None" denotes that the specific pin was not yet configured.
Example JSON String:
{'11': None, '10': None, '13': None, '12': None, '15': None, '14': None, '17': None, '16': None, '19': None, '18': None, '1': '1,', '0': None, '3': '0,', '2': '0,', '5': u'0,', '4': '0,', '7': '0,', '6': '0,', '9': '0,', '8': '0,'}
- Brian Xia - Initial work - YunIO
see the LICENSE.md file for details
- PyMOTW - on the lightweight Python server in Linino