Skip to content

Commit

Permalink
Added Pusher into node modules, created battery updater, single Alert…
Browse files Browse the repository at this point in the history
… with multiple actions.
  • Loading branch information
Mindrescu Ionut authored and Mindrescu Ionut committed Nov 9, 2019
1 parent 0dddc0d commit 8b910c7
Show file tree
Hide file tree
Showing 18 changed files with 9,758 additions and 454 deletions.
10 changes: 10 additions & 0 deletions app/Device.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Device extends Model
{
//
}
2 changes: 1 addition & 1 deletion app/Events/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ public function broadcastOn()

public function broadcastAs()
{
return 'sound-detected';
return 'device-alert';
}
}
30 changes: 0 additions & 30 deletions app/Events/BatteryAlert.php

This file was deleted.

15 changes: 9 additions & 6 deletions app/Http/Controllers/DeviceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Controllers;

use App\Events\{Alert, BatteryAlert};
use App\Events\{Alert, DeviceAlert};
use Illuminate\Http\Request;

class DeviceController extends Controller
Expand All @@ -12,16 +12,19 @@ public function alert(Request $request) {
$requestData = json_decode($request->getContent());

// check if data is sent by our TTN device
if(isset($requestData->app_id) && $requestData->app_id == 'wood-beacon') {
if (isset($requestData->app_id) && $requestData->app_id == 'wood-beacon') {
// define payload fields
$oPayloadFields = $requestData->payload_fields->message;

// broadcast the event with Pusher
event(new Alert($oPayloadFields));

// check the sent action
switch ($requestData->payload_fields->message->action) {
switch ($oPayloadFields->action) {
case 'sound-detected':
event(new Alert($requestData->payload_fields->message));
break;

case 'device-battery':
event(new BatteryAlert($requestData->payload_fields->battery));
case 'device-alert':
break;

default:
Expand Down
31 changes: 31 additions & 0 deletions database/migrations/2019_11_09_175045_create_devices_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateDevicesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('devices', function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('devices');
}
}
Loading

0 comments on commit 8b910c7

Please sign in to comment.