Ejemplo n.º 1
0
 public function run()
 {
     $newGateways = Gateway::getNewGatewayEuisFromInflux();
     foreach ($newGateways as $newGateway) {
         $newGateway->save();
     }
     $lastEntry = Gateway::getLastEntry();
     Gateway::updateGatewayStatusFromInflux($lastEntry->last_seen);
 }
Ejemplo n.º 2
0
<?php

/**
 * Local variables
 * @var \Phalcon\Mvc\Micro $app
 */
/**
 * Add your routes here
 */
$app->get('/', function () use($app) {
    $gateways = Gateway::find();
    $lastEntry = Gateway::getLastEntry();
    // this isn't 100% correct: if all gateways are down, the last update datetime won't be the same as the actual update time. Otherwise the update datetime could be up to gateway-update-interval off
    echo $app['view']->render('index', array('gateways' => $gateways, 'lastUpdate' => $lastEntry->last_seen));
});
$app->get('/gateways', function () use($app) {
    $response = new Phalcon\Http\Response();
    $response->setContentType('application/json');
    $gateways = Gateway::find();
    $gatewaysArray = array();
    foreach ($gateways as $gateway) {
        $gatewayArray = $gateway->toArray();
        unset($gatewayArray['ID']);
        $gatewaysArray[] = $gatewayArray;
    }
    // Pass the content of a file
    $response->setContent(json_encode($gatewaysArray));
    return $response;
});
$app->get('/gateways/{eui}', function ($eui) use($app) {
    $response = new Phalcon\Http\Response();