Ejemplo n.º 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     /**
      * @var Package $package
      */
     $package = Package::all()->random();
     $devices = Device::all();
     $installIds = $devices->pluck('push_id')->toArray();
     $this->info('App: ' . $package->app_name . '(' . $package->apk . ')');
     $this->info('Devices: ' . $devices->pluck('alias'));
     $this->line('===========================');
     $result = $this->client->push()->setPlatform(M\all)->setAudience(M\registration_id($installIds))->setMessage(M\message($package->toJson(), null, "package"))->send();
     $this->info('Push success');
     //        print_r($result->response->body);
     //        $msg_ids = $result->msg_id;
     //        $report = $this->client->report($msg_ids);
     //        print_r($report->received_list);
     $push = new Push();
     $push->package_id = $package->id;
     $push->user_id = 4;
     $push->sendno = $result->sendno;
     $push->msg_id = $result->msg_id;
     $push->is_ok = $result->isOk;
     $push->save();
     print_r($push->toJson());
 }
Ejemplo n.º 2
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create()
 {
     $devices = Device::all();
     \Excel::create("Device List", function ($excel) use($devices) {
         $excel->sheet('Sheet1', function ($sheet) use($devices) {
             $sheet->fromModel($devices, null, 'A1', true);
         })->download('xls');
     });
 }
Ejemplo n.º 3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $all_emp = Employee::all();
     $dev_number = Device::all()->count();
     $dev_list = range(1, $dev_number);
     foreach ($all_emp as $employee) {
         $employee->devices()->attach($dev_list[array_rand($dev_list)]);
     }
 }
Ejemplo n.º 4
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $devices = Device::all();
     $connected_device = Device::find(1);
     if (Connected::find(1) == null) {
         $connected_device = Connected::Create(['ip_address' => '127.0.0.1', 'device_id' => 0, 'connected' => 0]);
     }
     $connected_device = Connected::find(1);
     return view('pages.home', compact('devices', 'connected_device'));
     // ->with(['devices' => $devices, 'conne']);
 }
Ejemplo n.º 5
0
 /**
  * Display list device be assigned to
  * 
  * @return Response view
  */
 public function index()
 {
     $devices = Device::all();
     $employees = Employee::all();
     $employall = array();
     $employall += array('0' => 'None');
     foreach ($employees as $key => $value) {
         $employall += array($value->id => $value->lastname . " " . $value->firstname);
     }
     $statusall = StatusDevice::lists('status', 'id');
     return view('devices.borrow', compact('devices', 'employall', 'statusall'));
 }
Ejemplo n.º 6
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     // Grace period for arduinos to send info
     $grace = 36000;
     // Data for the view
     $data = ['live' => [], 'missing' => []];
     $devices = Device::all();
     foreach ($devices as $key => $device) {
         // device->updated_at is Carbon object, need to change to timestamp
         if ($device->updated_at->timestamp <= time() - $grace) {
             $data['missing'][] = $device;
         } else {
             $data['live'][] = $device;
         }
     }
     view()->share('live', $data['live']);
     view()->share('missing', $data['missing']);
 }
Ejemplo n.º 7
0
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
    // Grace period for arduinos to send info
    $grace = 36000;
    // Data for the view
    $data = ['live' => [], 'missing' => []];
    // Puntos para las gráficas
    $points = [];
    $devices = Device::all();
    foreach ($devices as $key => $device) {
        // device->updated_at is Carbon object, need to change to timestamp
        if ($device->updated_at->timestamp <= time() - $grace) {
            $data['missing'][] = $device;
        } else {
            $data['live'][] = $device;
        }
    }
    // dd($data);
    // De los live sacar los puntos para las gráficas
    foreach ($data['live'] as $device) {
        foreach ($device->sensors as $sensor) {
            // $points['arduino1']['2015-07-19 14:30']['humedad1'] = 35
            //$points[$device->name]['by_date'][$sensor->created_at->toDateTimeString()][$sensor->type] = $sensor->value;
            // $points['arduino1']['humedad1'][] = ['2015-07-19 14:30', 35]
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $devices = Device::all();
     return View('devices.index', compact('devices'));
 }
Ejemplo n.º 9
0
 /**
  * Export to excel list device
  * 
  * @return file excel
  */
 public function exportExcel()
 {
     Excel::create('List Device', function ($excel) {
         $excel->sheet('Sheetname', function ($sheet) {
             $sheet->setBorder('A1:K1', 'thin');
             $sheet->cells('A1:K1', function ($cells) {
                 $cells->setBackground('blue');
                 $cells->setFontColor('#FFFFFF');
                 $cells->setAlignment('center');
                 $cells->setValignment('middle');
                 $cells->setFontFamily('Times New Roman');
             });
             $sheet->setFontFamily('Times New Roman');
             $sheet->setWidth(array('A' => '10', 'B' => '20', 'C' => '20', 'D' => '20', 'E' => '20', 'F' => '20', 'G' => '40', 'H' => '20', 'I' => '30', 'J' => '20', 'K' => '20'));
             $data = [];
             /*HEADER EXCEL*/
             array_push($data, array('STT', 'NAME DEVICE', 'SERIAL DEVICE', 'RECEIVE DATE', 'STATUS'));
             /*CONTENT EXCEL*/
             $device = Device::all();
             $number = 0;
             foreach ($device as $key => $value) {
                 $device[$key]->device_name = KindDevice::find($value->kind_device_id)->device_name;
                 $device[$key]->status = StatusDevice::find($value->status_id)->status;
                 $device[$key]->employee_code = Employee::find($value->employee_id)->employee_code;
                 $number++;
                 array_push($data, array($number, $value->device_name, $value->serial_device, $value->receive_date, $value->status, $value->distribution));
             }
             $sheet->fromArray($data, null, 'A1', false, false);
         });
     })->download('xls');
 }
Ejemplo n.º 10
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //
     $devices = Device::all();
     return view('devices.index')->with('devices', $devices);
 }
Ejemplo n.º 11
0
 public function getDeviceAllHtml()
 {
     $devices = Device::all();
     $i = 1;
     foreach ($devices as $row) {
         echo '<tr>' . '<td>' . $i++ . '</td>' . '<td>' . $row['id'] . '</td>' . '<td>' . $row['device_name'] . '</td>' . '<td>' . $row['ip_address'] . '</td>' . '<td>' . $row['soap_port'] . '</td>' . '</tr>';
     }
 }
Ejemplo n.º 12
0
 public function createFile($id)
 {
     $users = User::all();
     $client = Client::where('id', $id)->get();
     $modele = Modeles::with('category', 'brand', 'articles')->get();
     $devices = Device::all();
     $articles = Article::all();
     $supp = Supplier::all();
     $categories = Category::all();
     $brands = Brand::all();
     $leftmenu['files'] = 'active';
     return view('/files/create-by-id', ['leftmenu' => $leftmenu, 'client' => $client[0], 'modeles' => $modele, 'devices' => $devices, 'articles' => $articles, 'suppliers' => $supp, 'categories' => $categories, 'brands' => $brands, 'users' => $users]);
 }
 public function devices()
 {
     $devices = Device::all();
     return response()->json($devices);
 }
Ejemplo n.º 14
0
 /**
  * Get count of all devices.
  * @return int Count of all devices.
  */
 public function getCount()
 {
     return \App\Device::all()->count();
 }
Ejemplo n.º 15
0
 /**
  * Checks the list of all devices and return 1 if the device
  * with the specified ip is found, or 0 othewise
  * @param  string $ip - ip address to search
  * @return integer $result - the result of the operation
  */
 public function checkIp($ip)
 {
     $result = Device::all()->where('ip_address', $ip)->count();
     return $result;
 }
Ejemplo n.º 16
0
    // -27.49611, 153.00207 -> brisbane
    $lat = 48.842147;
    $lon = 2.321984;
    $radius = 3;
    $places = \App\Place::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->having('distance', '<', $radius)->orderby('distance', 'asc')->with('ranks', 'ranks.category')->get();
    return view('places.index', compact('places'));
});
Route::group(array('prefix' => 'api/v1'), function () {
    Route::post('/devices', function () {
        // Save the device
        $data = \Illuminate\Support\Facades\Input::all();
        $device = \App\Device::firstOrCreate($data);
        return response()->json($device);
    });
    Route::get('/devices', function () {
        $devices = \App\Device::all();
        return response()->json($devices);
    });
    Route::get('/nearby', function () {
        // -27.49611, 153.00207 -> brisbane
        $lat = \Illuminate\Support\Facades\Input::get('lat', -27.49611);
        $lon = \Illuminate\Support\Facades\Input::get('lon', 153.00207);
        // Check if a valid location
        $radius = 25;
        $city = \App\City::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->having('distance', '<', $radius)->orderby('distance', 'asc')->first();
        if (!$city) {
            abort(400, 'City not supported.');
        }
        $radius = 1.5;
        $places = \App\Place::select(DB::raw("*, (6371 * acos( cos( radians({$lat}) ) * cos( radians( latitude ) ) * cos( radians( {$lon} ) - radians(longitude) ) + sin( radians({$lat}) ) * sin( radians(latitude) ) )) AS distance"))->having('distance', '<', $radius)->orderby('distance', 'asc')->with('ranks', 'ranks.category')->get();
        return response()->json($places);