Author Topic: Non-javascript access to widgets (bash / Linux / scripting)  (Read 972 times)

dfsmith

  • Newbie
  • *
  • Posts: 3
It wasn't too easy to figure this out, but here's a bash script to write a message to my LCD display.  No javascript or client stuff required.  You will also need date (GNU), wget and hexdump (which are fairly standard utilities---date needs the +%s format option).

Edit the parsewidget function to set your own friendly names.

Enjoy!
(Modified to take multiple messages and to improve performance.)
 

#!/bin/bash
# Daniel F. Smith, iobridge@dfsmith.net
#
# Usage:
#    iobridge.sh <widget> message [message...]
#
# The <widget> argument can be the widgetID or a friendly name
# (see the parsewidget function).  If the friendly name starts   
# with "lcd", then some convenient substitutions will be made
# to the message (see the parsemessage function).
#
# E.g.,
#    ./iobridge.sh lcd '%clear%Hello world!'
#    ./iobridge.sh servo 400 2000 400
#    ./iobridge.sh wuQRD6ENmrDq 1000
...


Note

The code has now been moved to the wiki so that there aren't multiple versions floating around.  See
http://www.iobridge.net/wiki/api/shell-scripting-non-javascript-widget-control-api

« Last Edit: June 09, 2009, 01:06:56 AM by dfsmith »

jason

  • Administrator
  • Hero Member
  • *****
  • Posts: 502
    • ioBridge.com
Re: Non-javascript access to widgets (bash / Linux / scripting)
« Reply #1 on: June 06, 2009, 02:13:37 PM »
This is great!  ;D  Thanks for putting the time into this.  Have you tried any other types of widgets?  We need to put this in the wiki.
Jason Winters
ioBridge Developer

dfsmith

  • Newbie
  • *
  • Posts: 3
Re: Non-javascript access to widgets (bash / Linux / scripting)
« Reply #2 on: June 06, 2009, 04:04:58 PM »
I also tried it with my servo widget and it works.  If a little slow... (no dancing robots for now).

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 668
    • ioBridge Support
Re: Non-javascript access to widgets (bash / Linux / scripting)
« Reply #3 on: June 08, 2009, 06:08:40 PM »
This is great, thanks for writing the API entry in the Wiki.

http://www.iobridge.net/wiki/api/shell-scripting-non-javascript-widget-control-api

To speed things up, you could hang onto the Session and Action ID's. They are valid with activity for multiple instances of the widget. So, if you retained them it would cut your transaction time in half.
ioBridge Support
Community Team

dfsmith

  • Newbie
  • *
  • Posts: 3
Re: Non-javascript access to widgets (bash / Linux / scripting)
« Reply #4 on: June 09, 2009, 01:21:33 AM »
It does take multiple messages with the same sessionID etc.

Now I'm trying to figure out how to get the press of a button (or buttons) to activate a server script.  I've looked at the Javascript and it appears that the real-time widgets use a partial polling method (as opposed to an AJAX-like approach).  There is also the email method.

So, from Iobridge's side, which is the preferred method?
  • Partial-polling multiple widgets
  • Lots of emails
  • Active polling of the module status (with a flip-flop to capture the button press)

It would be nice if the module could issue local ethernet broadcast messages when status changes.  I realize you probably have higher priorities....

(Incidentally, the real-time widgets have a memory leak under my Firefox3; the <head> keeps getting more and more <script> tags over time.  Refreshing the page might cause a button press to be missed, so it's not really suitable for long-term monitoring.)

Ollie

  • Newbie
  • *
  • Posts: 19
Re: Non-javascript access to widgets (bash / Linux / scripting)
« Reply #5 on: June 08, 2010, 12:24:29 PM »
Is the example code for iobridge.sh (now in the Wiki) still valid?  I am trying to run a very simple test that turns on/off an X10 module but have not had any luck.

I am using the syntax:  ./iobridge.sh <my_widget's_id> 0   <or 1 to turn it on>

If I echo the $actionurl in the script, it only shows up as "&setValue=%30&dt=127601399xxxx"   I would think there should be more but I'm not quite bash savvy enough to go beyond this point.   In short, the $actionbaseurl appears to be null.

Ollie

Ollie

  • Newbie
  • *
  • Posts: 19
Re: Non-javascript access to widgets (bash / Linux / scripting)
« Reply #6 on: June 09, 2010, 11:24:05 PM »
I gave up on the bash script in the wiki example.  I am using iobridge-proxy.php instead and it is doing exactly what I want.

iobridge

  • Administrator
  • Hero Member
  • *****
  • Posts: 668
    • ioBridge Support
Re: Non-javascript access to widgets (bash / Linux / scripting)
« Reply #7 on: June 10, 2010, 09:01:49 AM »
You can also use the Static Widget API:

http://www.iobridge.net/wiki/api/static-widget-api

All you need is the widgetID and parameters, the API will access the widget and/or control the widget. No need to parse JavaScript and write a custom PHP script. You can do anything that the widgets can do thru this API.
ioBridge Support
Community Team