Databases are NOT useless! Besides all the data enforcement, I want to plot
things and store logs and variables. This is a silly thing to say.

If you are firmly against storing any data, for any reason, take the
following boilerplate ajax call (in your web page):

function showMeData(data) {

    console.log(data); // or do whatever else you want here

}

function myAjaxFunction(sensorname,callback){
$.ajax({
    var callback=showMeData;
    url: "/wsgireadsensor",
    type: "post",
    datatype:"json",
    data: {'sensorname':sensorname},
    success: function(response){
    // Execute our callback function
        callback(response);
    }
});

myAjaxFunction('blurgety-bloog',showMeData)


Put your rendering/processing in showMeData, and call myAjaxFunction
whenever you want. It is non-blocking (or not, if you want).

All you need is a wsgi script on your server called "wsgireadsensor":


def application(environ, start_response):
    import cgi, json
    from mylib import readowserversensor

    post_env = environ.copy()
    post_env['QUERY_STRING'] = ''
    post = cgi.FieldStorage(
        fp=environ['wsgi.input'],
        environ=post_env,
        keep_blank_values=True
    )

    # Get the form data
    formname=post.getvalue('name')
    data={}
    d={}
    for k in post.keys():
        d[k] = post.getvalue(k)

    status = '200 OK'

    # Run stuff as requested
    if 'sensorname' in d :
        data['result']= readowserversensor(d['sensorname'])
        if data['result']:
            data['status']='success!'
        else:
            data['status']='fail!'
    else:
        data=['empty']

    output = json.dumps(data,indent=1)
    response_headers = [('Content-type', 'application/json')]
    start_response(status,response_headers)
    return [output]

Enable mod_wsgi and pop "WSGIScriptAlias /wsgisreadsensor
/mydirectoryforwsgiscripts" into your apache site configuration and
you're done. The data is returned to your web page call as json.


See here for details:
http://www.cupidcontrols.com/2014/01/creating-a-responsive-user-interface-updating-browser-data-in-real-time-using-jquery-and-ajax/


Colin





On Tue, Mar 18, 2014 at 4:17 PM, Michael Markstaller <[email protected]> wrote:

> After some hours of investigation, I think implementing JSONP (again,
> note the P!) in owhttpd looks like the best solution(?)
> This would IMHO also be useful for some other solutions maybe to avoid
> useless workarounds like writing DB's and then query the same..
>
> I'm willing to try do it (though limited C know-how) like /json /text
> just /jsonp.
>
> Any thoughts still welcome, the question is still: how to get values
> from owfs/owserver directly without using crude workarounds like writing
> a DB first etc ;)
>
> Michael
>
>
> ------------------------------------------------------------------------------
> Learn Graph Databases - Download FREE O'Reilly Book
> "Graph Databases" is the definitive new guide to graph databases and their
> applications. Written by three acclaimed leaders in the field,
> this first edition is now available. Download your free book today!
> http://p.sf.net/sfu/13534_NeoTech
> _______________________________________________
> Owfs-developers mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/owfs-developers
>
------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Owfs-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/owfs-developers

Reply via email to