Getting back actual time from emoncms

Hi,

is it possible to request the actual time via api-interface?

I am using the api-Interface with an arduino, exchanging data over the api-interface. (sending input values and so on)

To get the actual time for the arduino, i am just thinking for a way to get it from my emoncms-server.
OK, i could use a RTC or NTP-Server, but this is additional hardware, or communication interface. Would be great, if I could use already available communication.

brutzler's picture

Re: Getting back actual time from emoncms

Hi,

after long search, I decided to make this change in the feed_controller.php:

                $f = $feed->get($feedid);
                // if public or belongs to user
                if ($f['public'] || ($session['userid']>0 && $f['userid']==$session['userid'] && $session['read']))
                {
                    if ($route->action == "value") $result = $feed->get_value($feedid);
                    if ($route->action == "timevalue") $result = $feed->get_timevalue_seconds($feedid);
                    if ($route->action == "get") $result = $feed->get_field($feedid,get('field')); // '/[^\w\s-]/'
                    if ($route->action == "aget") $result = $feed->get($feedid);

                    if ($route->action == 'histogram') $result = $feed->histogram_get_power_vs_kwh($feedid,get('start'),get('end'));
                    if ($route->action == 'kwhatpower') $result = $feed->histogram_get_kwhd_atpower($feedid,get('min'),get('max'));
                    if ($route->action == 'kwhatpowers') $result = $feed->histogram_get_kwhd_atpowers($feedid,get('points'));
                    if ($route->action == 'data') $result = $feed->get_data($feedid,get('start'),get('end'),get('dp'));
                    if ($route->action == 'average') $result = $feed->get_average($feedid,get('start'),get('end'),get('interval'));
                    if ($route->action == 'time') $result = time();                                                                      
                }

On sending:
http://192.168.1.80/emoncms/feed/time.json?id=25&apikey=123xyz
I get back the actual UNIX-time-stamp.

Its only working, if I add a valid feed-ID.

Anyone a better idea?

brutzler's picture

Re: Getting back actual time from emoncms

Edit:

here its better (no feed-id necessary)

The change is in line 113 of feed_controller.php

            else
            {
                $result = array('success'=>false, 'message'=>'Feed does not exist');
                 if ($route->action == "time") $result = time();  
            }
        }
    }

    return array('content'=>$result);

with
http://192.168.1.80/emoncms/feed/time.json
I get back the UNIX-timestamp

----------------------------------------------
I did one post between. Where is it????

Moderators Note >> Stuck in the moderation queue! - now published! 
Paul

 

 

brutzler's picture

Re: Getting back actual time from emoncms

Or makes it even more readable ;-)

if ($route->action == "time") $result = date("d.m.Y - H:i",time()); 

Result:
"12.01.2015 - 00:35"

 

Comment viewing options

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