controlling a device with button-widget possible? --> packet-generator?

Hi,

I have seen, there is a button widget in emoncms.
But til now no useful help to this item found.

Is it possible to make any outgoing reaction (TCP-telegram or similiar) when the button is pressed?
I tried to use the button widget within a dashboard, but with no success.
Configuring the button, he asks on a feed??? How to create such a feed? Always thought feeds are incoming datas.

Thx, in advance, for your replies.

 

 

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Hi,

wish you all a happy new year :-)

In the meantime, I have found, that outgoing reactions will only work with the RFM12 packet generator.

Looks, as if this is of no use for me, because i have an own arduino with wlan-interface, who is sending temperature-datas over ethernet to emoncms, using bulk.json comands.

If there would be a possibility, to send out a tcp-telegram like "method=get" or something else from emoncms to the arduino, I could decode them and control binary outputs over this.

Does somebody have any experience in this??

EDIT:
I would like to test for myself, but I nowhere found any hint how to install/integrate the packetgen-modul into emoncms 8.4.0.
There is only some tips or a ready to use image for a rasp-pi, but my emoncms is running on a windows7-server :-(

 

 

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Hi, All the "emoncms modules" follow a similar installation method, you need to clone that modules repo from git into the emoncms/Modules folder and then open emoncms in your browser => Admin => Update & check.

You should also take a look at the events module as that can react to a feed (switched state) and send a request, email, publish to mqtt or just update another feed etc.

I have been playing with the button-widgets too and now have feeds set up for several buttons and can poll those feeds by feedid to establish their state, 1 or 0 at a regular interval individually using a "value" feed api url or several at once using the recently added "fetch" api.

I've made a couple of changes to the button-widget code to get it working and will submit a pull req once tested.

I'm currently having issues getting the events module to play ball.

Paul

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Hi,

got it installed. Now i have a new pulldown with Extras->RFM12b Packet Generator.

>> I have been playing with the button-widgets too and now have feeds set up for several buttons and can poll those feeds by feedid to establish their state, 1 or 0 at a regular interval individually using a "value" feed api url or several at once using the recently added "fetch" api.

A little bit hard to understand for me :-(  (totaly new stuff and different language)
You talk about "poll". Does this mean, I have to send a feed-telegram to emoncms to get back the state of an item?
I think it would be easier to understand, if i would have an example, that i could examine. Is there anywhere such an example?

EDIT:
OK got event-module installed too. Think, this is could be a way for me.
I already was able to send some information to my arduino, using the "call url" methode. (the arduino is listening as server)

What I did:

- Create a new input, create a feed from this input (log-feed)
- Make a button with this feed.
- Control this button with commands:
--> switch off: http://192.168.1.80/emoncms/input/bulk.json?data=[[0,3,0]]&apikey=...
--> switch on: http://192.168.1.80/emoncms/input/bulk.json?data=[[0,3,1]]&apikey=...
- as a result the button is changing between red and green.
- Set up an event: if "feed" > 0 call url......
--> On changing from 0->1 i get an outgoing telegram to my arduino-server

Thats very good so far :-)))

 

BUT: I completely do not realize, how to make any changes on a variable or feed from a dashboard.

When i integrate a button, then I can assign a feed and a starting value. But after storing the dashboard, i can not see any reaction on pressing the button... :-(

EDIT 2nd:

One step further:
Creating the button without writing a startvalue makes more success.
I can switch the button by clicking on it from red to green (0->1).
But after a few seconds it is switching back to "0", and the event is not reacting too. It does not see the change from 0 -> 1

 

 

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

I'm currently struggling a bit with this too,

I think we may want the same result but going about it different ways. my "poll" reference was basically I can currently use 

        http://CMS.IP.OR.URL/emoncms/feed/value.json?id=123&apikey=1a2b3c4etc

to get the current value (status) of a feed or 

        http://CMS.IP.OR.URL/emoncms/feed/fetch.json?ids=123,124,125,126&apikey=1a2b3c4etc 

to return a batch of values (statuses).

This is similar to how packetgen works, in that the "packetgen hack" for emonhub "polls" the packetgen module every 5 seconds and returns the values set in the packetgen gui, except this works on the feed data directly.

The button widgets are "quirky" and I have made progress with improving their function, I have then switching the feed value from 1 to 0 or 0 to 1 no problem, I also have the button colour changing with the feed value rather than displaying the last "status set by that button" which is handy as I am also able to set/change the feed values remotely using the feeds api and the button colours change on the dashboard. I have also incorperated an "interim colour" eg if the button is green and it is clicked the button instantly turns pink to acknowledge the click and then when the page is refreshed/re-rendered it will change colour again,to red confirming the feed has actually changed, the same happens using yellow before green in the opposite direction.

The events module however is a different matter, I can use the "test" function but as soon as I set any events I can no longer update the feed being monitored, I just get an error and thats where I'm currently at.

I cannot be sure if the events module isn't working because of something I've changed or not, so until I fix that I'm unsure if the button stuff is any good. Progress is painfully slow at the moment as I'm not good with the php, js or sql, let alone the 3 combined.

Paul

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Hi Paul,

ok.

Do you want to share your actual button code with me?
I am not good with php too, but perhaps it is helpful to view the stuff from a different pair of eyes?

 

EDIT:
I tested your "polling-methode". Thats pretty easy, and I think this is the better way for me too, because I do not need to setup a tcp-server on my arduino. I can use the existing tcp-client to poll values in the same way as I send data to emoncms. --> No need for me any more to use the event module ;-)
Now I have only the problem, that my buttons do not hold the actual state. They are always switching back to the last input value, when I change them from the dashboard.
Looks like you do not have the same problem? Is this because of your code-changes, or do i use the widget in a wrong way?

EDIT2:
Can it be, that on clicking the button in a dashboard, only the color of the button is changed and the feed-value stays at the old value? And then after a few seconds the dashboard is refreshed and takes the value from the feed?

EDIT3:
I think, that this feed.set(feedid,{'time':parseInt((new Date()).getTime()/1000),'value':outval}); is somehow not working proper?
To figure this out, I tried a few things with the API-commands (feed/set.json and feed/update.json), but had until now no success to get a new value into the feed or to change a feedvalue.

--> myIP/emoncms/feed/set.json?id=37&fields={'value':'123'}
returns a: {"success":false,"message":"Field could not be updated"}

--> myIP/emoncms/feed/update.json?id=37&time=UNIXTIME&value=100.0
returns a: null and I see a new timestamp in the feeds-table of the database. But the value is set to "0"

- Adding the &apikey=6565346546.... does not help :-(
- Is the syntax wrong?
- Or should the button-widget use an input-api instead of a feed-api to change a value?

 

 

 

 

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

I don't mind sharing at all I'm just not overly sure of what I'm at so things are being chopped about quite frequently.

This is what I have right now.

Firstly I noticed the set.json didn't have a "value" field for feed.set(feedid,{'time':parseInt((new Date()).getTime()/1000),'value':outval}); to use and so in emoncms/Modules/feed/feed_model.php I added 

if (isset($fields->value)) $array[] = "`value` = '".preg_replace('/[^\w\s-:]/','',$fields->value)."'";

immediately after if (isset($fields->public)) $array[] = "`public` = '".intval($fields->public)."'"; and also added 

if ($this->redis && isset($fields->value)) {$this->redis->hset("feed:$id",'value',$fields->value);

immediately after if ($this->redis && isset($fields->public)) $this->redis->hset("feed:$id",'public',$fields->public);

This allowed the button to update the feed, although this worked I have since discovered this wasn't the best way to do this and I'm looking at another method. But the button behavior was really quirky so.....

 

In emoncms/Modules/dashboard/Views/js/widgets/button/button_render.js I have changed var invalue = $(this).attr("value"); to  var invalue = assoc[feedname]; so that the "before click" status is taken from the feed value rather than a retained "status after last button click".

For that to work correctly I had to also change how the "value when rendered" is handled by adding

if (assoc[feed] !== assoc[feed]) {
    if ($(this).attr("value") !== $(this).attr("value")) $(this).attr("value",0); 
    assoc[feed] = $(this).attr("value");
    }  

immediately before var val = assoc[feed]; This will fetch the feed value and change null and undefined values to a zero and load  "assoc[feedname]" in preparation for the first click even if a "starting value" was not set in the widget settings.

I also changed draw_button(widgetcanvas[id], outval); to draw_button(widgetcanvas[id], outval + 4); as this line immediately changes the button colour, by adding the +4 a different colour is selected for the duration between clicking the button and the button re-rendering to display the correct colour based on reading the current feed value. 

This improved the button action 10 fold but the way the feed was being updated was wrong as that method was intended for settings and names etc not data. I worked this out the hard way as the events module kept failing.

Now I am playing with different ways of implementing an update function for the button to use, I have currently changed the feed.set(feedid,{'time':parseInt((new Date()).getTime()/1000),'value':outval}); line to feed.update(feedid,parseInt((new Date()).getTime()/1000),outval); and in emoncms/Modules/feed/feed.js I've added 

  'update':function(id, time, value)
  {
    var result = {};
    $.ajax({ url: path+"feed/update.json", data: "id="+id+"&time="+time+"&value="+value, async: false, success: function(data){} });
    return result;
  },

at line 75 (that function is just 3 lines starting "var", "$.ajax" and "return" - no line wrap)

I have since changed if ($route->action == "update") $result = $feed->update_data($feedid,time(),get("time"),get('value')); in emoncms/Modules/feed/feed_controller.php to

if ($route->action == "update") $result = $feed->update_data($feedid,time(),get("time"),null,get('value')); (all one line)

as it appears to pass one time value not the 2 as required by the ;public function update_data($feedid,$updatetime,$feedtime,$value). This seems to work correctly but will probably effect something else so probally isn't the best idea, plus I still can't get the events module to work.

I hope this makes some sense, maybe you can make some use of it too.

Paul

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

No I take that last bit back, it doesn't appear to be working. so I think we are at the same place. Trying to get 

feed.set(feedid,{'time':parseInt((new Date()).getTime()/1000),'value':outval});

to work with either feed/insert or feed/update (which I can't tell apart) 

Paul

edit - so to recap I can get the buttons to work smoothly and correctly both from the dashboard widget and from a url. I can establish the status of those feeds using a request, but the feed engines are not being used as the wrong api is being used, which also means the event module isn't informed when the feed is updated.

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Hi,

thx for your detailed explanation. Some things are logical for me.

But I think that there is something basicly wrong. Perhaps only on my emoncms-installation.

In my opinion, my first step should be to change/update values from the browser line via feed/api-comands.
As long as this is not working, all the other stuff is senseless. Do you agree?

Did you try this api-comands. Do you have a correct syntax for me. I only could use the Feed Api Help. And this is not working as expected. (See my last post)

I hope we do not talk past each other, but for me its a little bit hard to understand your explanations, because english is not my native language.

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

I have now removed that last edit as it was that "null" i added that broke the "update" for me, so

 I'm currently able to update from the browser address bar using urls

http://CMS.IP.OR.URL/emoncms/feed/update.json?id=10&time=1420328088&valu...

or

​http://CMS.IP.OR.URL/emoncms/feed/insert.json?id=10&time=1420328088&value=1&apikey=123abc

​Both work and the above changes from feed.set to feed.update are working again, I think !!

Your English is good, I think it's the topic not the language that makes it tricky.

Paul 

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Hi,

Change values from the browser:

update.json is not working @all
insert.json is working.

Based on this and your tips I only made 2 changes now:

1.)
Add this in feed.js:

    'insert':function(id, time, value)
  {
    var result = {};
    $.ajax({ url: path+"feed/insert.json", data: "id="+id+"&time="+time+"&value="+value, async: false, success: function(data){} });
    return result;
  },

2.)
Change the feed.set line in the button_render.js to this:

 //   feed.set(feedid,{'time':parseInt((new Date()).getTime()/1000),'value':outval});
    feed.insert(feedid,parseInt((new Date()).getTime()/1000),outval);

Now, I am able to change the button as needed. A klick toggles the state from 0->1 or the other way round.

And with
http://192.168.1.80/emoncms/feed/value.json?id=37&apikey=123abc
I get back the actual value ( "0" or "1")

Thats what I need to control a relay on the arduino from emoncms :-)

But you are right. Changing the feed-values do not have any affect on the event module. This is only reacting, if I make a value change on the input-value.

 

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

I think update is fussy about the timestamp, I think it will only work if the timestamp is greater than the last timestamp. try with the current unix timestamp and then add a couple of seconds and change the value => SEND then add couple more seconds and change the value => SEND again, see if that works for you.

 

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

I don't think it is a problem with the timestamp.

http://192.168.1.80/emoncms/feed/update.json?id=37&value=6&apikey=123abc --> :-(
http://192.168.1.80/emoncms/feed/insert.json?id=37&value=6&apikey=123abc --> :-)

Using the update.json without time-option, it makes an update in the mysql database with the actual timestamp, but changing the value to "0"

With insert.json its working great.

BUT: As soon, as I declare an event on this feed, I can not use the insert.json, or update.json api-calls at all.
I get back a Fatal error- (Look at the assigned screenshot).
Even there is an error, the feed value is updated on using the insert comand.

 

 

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

I experienced the same fatal error when trying to use the my first solution "set.json fields=value" which I suspected to be due to lack of timestamps. The events module is driven by the "last update" timestamp which is supplied by the "updated at time stamp" not the datapoint timestamp.

I have just tried switching browser to see if  get different results and the buttons are just black and not working in chrome. I think I'm spending far too much time on this now, see how I feel tomorrow :-(

Paul

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Coming back to my "idea" a few posts before.

What, if we do not update the feed value. If we update the input value?
Is there a chance to do this within the button_render.js?

Or can this cause different problems?

But i will go to sleep right now. Its 2:00 in the morning.....
 

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Had another stab at this and made a little more progress. I have made a created a "set_feed" function in feed.js

'set_feed':function(feedid,time,value)
  {
    var result = {};
    var apikeystr = ""; if (feed.apikey!="") apikeystr = "&apikey="+feed.apikey;
    $.ajax({                                      
      url: path+'feed/update.json?',                         
      data: "id="+feedid+"&time="+time+"&value="+value+apikeystr,
      async: false,                      
      success: function(data) {} 
    });
    return result;
  },

This is called from button_render.js by changing the feed.set line to

feed.set_feed(feedid,parseInt((new Date()).getTime()/1000),outval);

This seems to work ok! however I did get caught out when I took a break and came back to it as the open "dashboard" webpage doesn't refresh on timeout, so although I was effectively logged out (timed out) the webpage and the buttons continued to function but not update the feed due to lack of apikey. Once refreshed and logged in again the feed updates with the button clicks, I have been watching the feed in a realtime vis.

But still no joy from the events module and none of this seems to work in chrome so still a long way to go!

Paul

PS I haven't tried using the input api yet as that feels like extra steps to the same point. We would need to create an input, with a node id and a process list to "log to feed" and that process will just call the same "update_feed" function. The button is still attached to the feed rather than the input unless the code is dramatically changed. The inputs are not as robust as the feeds either so I will persevere for now, but haven't ruled out trying to use an input as a work around if all else fails.

 

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

>> We would need to create an input, with a node id and a process list to "log to feed" and that process will just call the same "update_feed" function.

[OffTopic]
Hmmm. I am missing the quote-function in this board :-(
[/OffTopic]

How do you make a button-feed without an input?
I only know the way to make an input-node and put a "log to feed" on it. And that was the base for all my coding the last days.

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

A feed can be created using a new input or even just created on the end of an existing inputs processlist and then immediately removed from the list, as this doesn't delete the actual feed, Likewise you could now delete the input along with its processing and the feed will remain.

Alternatively the feed api can be used, I created my "toggle_button" feeds using this url

http://CMS.IP.OR.URL/emoncms/feed/create.json?name=MyNewFeed&datatype=1&engine=2&apikey=123abc

​The engine type can be established by either examining the emoncms code or can be "copied" from existing feeds either via phpmyadmin or by listing your existing feeds with the api

http://CMS.IP.OR.URL/emoncms/feed/list.json&apikey=123abc.

​Paul

 

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Hi,

>>Likewise you could now delete the input along with its processing and the feed will remain.

No, I need the input, because I want to control the heater of my warmwaterboiler. Now I can make a request on this from emoncms (all over the world), my arduino takes this request and clears it via input-api. And the boiler is then running for a certain time (controlled by arduino). State of the boiler will be shown by a LED-widget.

BTW: Do you see a possibility to handover a time-setvalue to my arduino? Sending a number is not different as sending the control 0/1 (because its the same type of var). But how can I give in a dashboard the variable a defined value?

 

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

No, I need the input,

I wasn't saying you should, just answering your question how :-)

Although a feed can also be set or queried from all over the world without ann input, but if you want to display the status of the boiler rather than display the desired status an input would be required and that would be better driving an led-widget independent of the button or feed.

I'm not entirely sure what you mean by "time-setvalue" but if you want to send a value other than 1 or 0, you could write something custom or use feeds and input processing. eg if you want heater to run for 3 hours you could multiply the "1" by 3 for hours or 180 for mins etc and use the resulting feed value, you could even control that time value via an input or feed api. FeedA is controlled by button(0or1) x FeedB set via api to "TimePeriod" = 0 if button is off or whatever the "TimePeriod" is if on. 

If you are looking to use the actual time of day as a scheduler you would be far better off using cron to change the feeds status between 0 or 1 and use the button as a manual override. I have an artificial node set up using cron to provide values at predefined times via a web socket to emonhub. I call it CronNode and use it to switch energy tarrifs but it will soon be used to switch "control" feeds in exactly the same way.

Paul

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

And if you want to get the time the heater is switched on you can run 

http://CMS.IP.OR.URL/emoncms/feed/get.json?id=123&field="time"

after the change in state is detected.

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

And just to keep this up to date, the changes discussed that I previously reported as working from IE but not chrome, do actually work from chrome as long as I'm logged in.

Supplying the apikey in the api url does not work "fully" I have not figured it out yet but using the apikey in the url gives me a partial log-in, as in I can see the page but the buttons are all black and do not respond to clicks. I think this is now a different manifestation of the page appearing to function but not effecting the feeds in IE, seen when the session times out but the page doesn't refresh.

And the events module is still not working.

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

>>I'm not entirely sure what you mean by "time-setvalue"
I want to give my arduino from the dashboard an integer (= minutes) how long the heater should run, when it is started from emoncms.

The sequence of events should be:
dashboard: define a timeperiod in minutes, send this and a "heater-on-request" to my arduino.
arduino: receive the timeperiod and the request.
arduino: start the heater for the predefined time, and clear the request.
arduino: send status-information (heater on/off; remaining time) to emoncms-dashboard.

At now only missing an inputfield in emoncms for a number-value. e.g.120 (for 2hours)
Perhaps i will define several requests for different timeperiods.....

>>And the events module is still not working.
Yesterday I thought, I do not need this, because I can poll the values from emoncms. But this means, that there is always a time delay (in worst case the time between two polling events) between the action on the dashboard and the reaction on the arduino.
But the only option to this is to setup a server on my arduino and a working event-module......

>>If you are looking to use the actual time of day as a schedule...
No, and if, cron is not usable for me. I am using emoncms on a windows7-computer ;-)

 

Do you think, it is possible to make a copy of the button-widget, and rewrite the code, that the button2_events() does not make an api-call like feed.insert.....  but makes a "call url"
Something like this: http://192.168.1.80:8080/?sendstring

Likely the same as the event module makes on curl, but initiated directly from the button.

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

OK

to my last thought (send a call url from buttonklick)
I have never done something with js or ajax or similiar before emoncms. Therefore this will be somehow crazy.
But I have searched a lot in the web today, and have a "beginning" of a solution for me:

Knowing no better place, I have extended the feed.js with this function:
    'curltest':function()
  {
    var result = {};
        $.ajax({
            url: 'http://192.168.1.80:8080',
            data: {'request':1},
            dataType: 'xml',
            complete : function(){
                alert(this.url)
            },
            success: function(xml){
            }
        });
    return result;
  },

And then changed the feed-call in the button render.js with this:
    feed.curltest();

Whats the result? Every time I press the button, I get this on my server: (actually tested with SocketTest and Port 8080 on the same computer)

> New Client: 192.168.1.80
GET /?request=1 HTTP/1.1
Host: 192.168.1.80:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
Accept: application/xml, text/xml, */*; q=0.01
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://192.168.1.80/emoncms/dashboard/view
Origin: http://192.168.1.80
Connection: keep-alive

Using the event-testfunction it looks like this:
> New Client: 192.168.1.80
GET /?request=1 HTTP/1.1
Host: 192.168.1.80:8080
Accept: */*

> Client closed conection.

There is still some difference (above all the keep alive connection), but basicly I get a telegram to my tcp-server.

If somebody knows how to make this better, don't hesitate to tell.

My aim will be, to make a sort of button-widget which sends out a telegram on klicking, with a option for the url and the payload.
 

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

A little further: Why using a function for this.

I only take this codeline into the button_render.js:

        $.ajax({type:'GET', url:'http://192.168.1.80:8080', data: "request=1", timeout: 1000 });
 

with the timeout I get a connection close after one second.

Tomorrow I will create a new widget, with options (hopefully)

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Here again:

made a new widget for me: "curl_render.js".
Its a copy of the button_render.js with 4 parameters:

  • IP-adress
  • port
  • SendString
  • colour

Function: There will be drawn a circle of the defined colour. On klicking on the button, there is send a GET-Telegram to the defined IP/port.

If you want, you can test it and give me a feedback..

What is still making me angry, is that there is much more information sent, as using the curl from the event-module. (Look two posts above)
I studied the code of the event-test, but I do not see where is the difference.
Can somebody help here?
----------------------------------------------------------------------------------------------------------------------------
telegram caused by my $.ajax:
     $.ajax({type:'GET', url:'http://'+$(this).attr("IP")+':'+$(this).attr("port"), data: $(this).attr("payload"), timeout: 500 });   
------->
> New Client: 192.168.1.80
GET /?Heizung_EIN HTTP/1.1
Host: 192.168.1.80:8080
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
Accept: */*
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://192.168.1.80/emoncms/dashboard/view?id=2
Origin: http://192.168.1.80
Connection: keep-alive

> Client closed conection.
----------------------------------------------------------------------------------------------------------------------------
telegram made by the testbutton of the curl eventmodule:

> New Client: 192.168.1.80
GET /?Heizung_EIN HTTP/1.1
Host: 192.168.1.80:8080
Accept: */*

> Client closed conection.
----------------------------------------------------------------------------------------------------------------------------

I have figured out, that this function is initiated by the test-button (part of event_list.php):
  $(".testevent").click(function() {
    var eventid = $(this).attr("eventid");
    var feedid = $(this).attr("feedid");
    $.ajax({type:'GET',url:path+'event/test.json',data:'id='+eventid+'&feedid='+feedid,dataType:'json',success:function(){location.reload();}});
    return false;
  });

But I do not see something in here, that could be responsible for the difference (I tried the option "dataType" and "success"-> negative)

What do I have to change in my $.ajax-line to get the same?

 

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Good to see you are getting closer to a solution, I'm afraid I can't help you much with ajax or curl.

I suspect you have already examined the events module "curl code" Is it the header option and shorter timeout?

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

I thought it is the code in the event_list.php. Because i insertet an alert() into the  "$(".testevent").click(function()" (line 254 in event_list.php) , and saw it popping up on klicking the test-button.

Maybe its the header option, but i do not know how to change this php-code into js-code....

Its definitely not the timeout, because the value in php is in seconds and my value is in ms. -> Its the same

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Hi pb66,

no wasting more time to the difference in the curl-telegrams. I am only parsing them for my string. And this is working with both.

Now I finished my work so far. I can bidirect communicate with my arduino. Sending data via input-api and receive data (webserver on the arduino) via GET-telegrams from the curl-widget.

I have made some changes on my curl-widget. Its no more a round button, but a rect-button with different colours. In the appendix you can see how to setup the widget.
As I described, I get back from my arduino the infos whats the rest time the heater will stay on, and the state of the heater (LED)
I added another picture that shows the complete dashboard. Here you can see my modified cylinder-widget with 6 temperatures.

Hope you will get a solution for your problems soon ;-)

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

The dashboard looks very clear and functional, glad you got it working. I have enough functionality for what I need right now.

It would definitely be better if it was clear if the dashboards were fully logged in or not, but this is an existing dash characteristic. It has since dawned on me that any dash will remain active after a login has timed out. Normally with a display-only page there are no "clickable" widgets so you only notice the session has timed out when you try to navigate to anther emoncms page by the topmenu bar, nothing has changed but adding the toggle_buttons has highlighted the the need for an additional "if not-logged in go to login page" in the on-click perhaps. I will return to this another time probably.

The problems with the events module will save for another day too. I don't actually need it right now, I just wanted to see if I could get it to respond to a button for more options. But as I can't get it to function on non-button feeds either it isn't likely to be related so can wait.

It would be interesting to see your final changes, although I don't have a specific use right now I think your "curl-button" widget could be useful for other things since it's easily configured for different payloads and ports.

For example when a "socket to rfm network" interfacer gets implemented in emonhub, a "curl-button" could be configured to send a pre-prepared RFM packet to emonhub to be broadcasted out to nodes on the RFM network.

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

OK,

here it is. Feel free to copy or modify it. If you see something mismatch pls tell me.

pb66's picture

Re: controlling a device with button-widget possible? --> packet-generator?

Thanks, So are all the changes contained in one widget file and picked up by the existing "dash" code? or did you make any other changes?

brutzler's picture

Re: controlling a device with button-widget possible? --> packet-generator?

You only need the widget-file. Copy it into the widget-folder, and you can use it at once with the existing dashboard.  I changed all instances to "curl", so there should be no interference to the other widgets.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.