Commit 09cd691c authored by Erika Heidi's avatar Erika Heidi

Initial commit

parents
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.yml]
indent_style = space
indent_size = 2
* text=auto
.travis.yml export-ignore
.styleci.yml export-ignore
.scrutinizer.yml export-ignore
BACKERS.md export-ignore
CONTRIBUTING.md export-ignore
CHANGELOG.md export-ignore
/vendor
/.idea
/.vscode
/.vagrant
/config/app.php
test*.php
The MIT License (MIT)
Copyright (c) Nuno Maduro <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
#LOLBox
Experimental project using serial communication to talk with Arduino devices using PHP code.
\ No newline at end of file
<?php
/**
* Sends a static message to be displayed in the LedBox
*/
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
use Heidilabs\SerialDriver;
class DisplayMessage extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'display:message {message}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Displays a static message on the LedBox.';
private $serial;
/**
* Execute the console command.
*
* @return void
*/
public function handle(): void
{
$message = $this->argument('message');
$this->comment("Sending message: $message");
/** @var SerialDriver $serial */
$serial = app(SerialDriver::class);
$serial->sendMessage($message);
$serial->close();
}
/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
*/
public function schedule(Schedule $schedule): void
{
// $schedule->command(static::class)->everyMinute();
}
}
<?php
namespace App\Commands;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
class InspiringCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'inspiring {name=Artisan}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Display an inspiring quote';
/**
* @var
*/
private $serial;
/**
* Execute the console command.
*/
public function handle(): void
{
$this->info('Simplicity is the ultimate sophistication. - Leonardo da Vinci');
$this->notify("Hey {$this->argument('name')}", 'Enjoy the fresh air!');
}
/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*/
public function schedule(Schedule $schedule): void
{
// $schedule->command(static::class)->everyMinute();
}
}
<?php
namespace App\Commands;
use Heidilabs\SerialDriver;
use Illuminate\Console\Scheduling\Schedule;
use LaravelZero\Framework\Commands\Command;
use TTools\App as TTools;
class TweetMonitor extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'tweet:monitor {tweetId?}';
/**
* The description of the command.
*
* @var string
*/
protected $description = 'Uses the Twitter API to display info about a specific tweet (likes and RTs)';
/**
* Execute the console command.
*
* @return void
*/
public function handle(): void
{
/** @var TTools $ttools */
$ttools = app(TTools::class);
/** @var SerialDriver $serial */
$serial = app(SerialDriver::class);
$tweetId = $this->argument('tweetId');
if (!$tweetId) {
$credentials = $ttools->getCredentials();
$userinfo = $ttools->get('/users/show.json', [ 'screen_name' => $credentials['screen_name'] ]);
$tweetId = $userinfo['status']['id_str'];
}
//this will run as a loop to fetch tweet every 30s
while (true) {
$this->comment("Fetching tweet info for tweet $tweetId...");
$info = $ttools->get('/statuses/show.json', [ 'id' => $tweetId ]);
$tweet = $info['text'];
$rts = $info['retweet_count'];
$favs = $info['favorite_count'];
$this->info($tweet);
$message = "Stats: $rts RTs, $favs Likes";
$this->comment($message);
$serial->sendMessage($message);
$this->comment("Now sleeping...");
sleep(30);
}
}
/**
* Define the command's schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
*/
public function schedule(Schedule $schedule): void
{
// $schedule->command(static::class)->everyMinute();
}
}
<?php
namespace App\Providers;
use Heidilabs\SerialDriver;
use Illuminate\Support\ServiceProvider;
use TTools\App as TTools;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot(): void
{
//
}
/**
* Register any application services.
*/
public function register(): void
{
$this->app->singleton(SerialDriver::class, function($app) {
return new SerialDriver(config('app.serialPort'), config('app.baudRate'));
});
$this->app->singleton(TTools::class, function($app) {
return new TTools(config('app.ttools'));
});
}
}
<?php
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| The first thing we will do is create a new Laravel application instance
| which serves as the "glue" for all the components of Laravel, and is
| the IoC container for the system binding all of the various parts.
|
*/
$app = new LaravelZero\Framework\Application(
dirname(__DIR__)
);
/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
|--------------------------------------------------------------------------
|
| Next, we need to bind some important interfaces into the container so
| we will be able to resolve them when needed. The kernels serve the
| incoming requests to this application from both the web and CLI.
|
*/
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
LaravelZero\Framework\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
Illuminate\Foundation\Exceptions\Handler::class
);
/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/
return $app;
*
!.gitignore
\ No newline at end of file
{
"name": "laravel-zero/laravel-zero",
"description": "The Laravel Zero Framework.",
"keywords": ["framework", "laravel", "laravel zero", "console", "cli"],
"homepage": "https://laravel-zero.com",
"type": "project",
"license": "MIT",
"support": {
"issues": "https://github.com/laravel-zero/laravel-zero/issues",
"source": "https://github.com/laravel-zero/laravel-zero"
},
"authors": [
{
"name": "Nuno Maduro",
"email": "[email protected]"
}
],
"require": {
"php": "^7.1.3",
"hyperthese/php-serial": "^1.0",
"laravel-zero/framework": "5.6.*",
"ttools/ttools": "^3.1"
},
"require-dev": {
"phpunit/phpunit": "^7.1"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Heidilabs\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true,
"platform": {
"ext-posix": "0"
}
},
"scripts": {
"post-create-project-cmd": [
"@php application app:rename"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"bin": ["lolbox"]
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
return [
/*
|--------------------------------------------------------------------------
| Application Name
|--------------------------------------------------------------------------
|
| This value is the name of your application. This value is used when the
| framework needs to place the application's name in a notification or
| any other location as required by the application or its packages.
|
*/
'name' => 'lolbox',
/*
|--------------------------------------------------------------------------
| Application Version
|--------------------------------------------------------------------------
|
| This value determines the "version" your application is currently running
| in. You may want to follow the "Semantic Versioning" - Given a version
| number MAJOR.MINOR.PATCH when an update happens: https://semver.org.
|
*/
'version' => app('git.version'),
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services your application utilizes. Should be true in production.
|
*/
'production' => false,
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => [
App\Providers\AppServiceProvider::class,
],
/*
* Serial Device Settings
*/
'serialPort' => '/dev/ttyUSB0',
'baudRate' => 19200,
/*
* Twitter API (TTools lib) Settings
*/
'ttools' => [
'consumer_key' => 'CONSUMER_KEY',
'consumer_secret' => 'CONSUMER_SECRET',
'access_token' => 'ACCESS_TOKEN',
'access_token_secret' => 'ACCESS_TOKEN_SECRET',
],
];
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Command
|--------------------------------------------------------------------------
|
| Laravel Zero will always run the command specified below when no command name is
| provided. Consider update the default command for single command applications.
| You cannot pass arguments to the default command because they are ignored.
|
*/
'default' => NunoMaduro\LaravelConsoleSummary\SummaryCommand::class,
/*
|--------------------------------------------------------------------------
| Commands Paths
|--------------------------------------------------------------------------
|
| This value determines the "paths" that should be loaded by the console's
| kernel. Foreach "path" present on the array provided below the kernel
| will extract all "Illuminate\Console\Command" based class commands.
|
*/
'paths' => [app_path('Commands')],
/*
|--------------------------------------------------------------------------
| Added Commands
|--------------------------------------------------------------------------
|
| You may want to include a single command class without having to load an
| entire folder. Here you can specify which commands should be added to
| your list of commands. The console's kernel will try to load them.
|
*/
'add' => [
// ..
],
/*
|--------------------------------------------------------------------------
| Hidden Commands
|--------------------------------------------------------------------------
|
| Your application commands will always be visible on the application list
| of commands. But you can still make them "hidden" specifying an array
| of commands below. All "hidden" commands can still be run/executed.
|
*/
'hidden' => [
NunoMaduro\LaravelConsoleSummary\SummaryCommand::class,
Symfony\Component\Console\Command\HelpCommand::class,
Illuminate\Console\Scheduling\ScheduleRunCommand::class,
Illuminate\Console\Scheduling\ScheduleFinishCommand::class,
Illuminate\Foundation\Console\VendorPublishCommand::class,
],
/*
|--------------------------------------------------------------------------
| Removed Commands
|--------------------------------------------------------------------------
|
| Do you have a service provider that loads a list of commands that
| you don't need? No problem. Laravel Zero allows you to specify
| below a list of commands that you don't to see in your app.
|
*/
'remove' => [
// ..
],
];
#!/usr/bin/env php
<?php
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/
$autoloader = require file_exists(__DIR__.'/vendor/autoload.php') ? __DIR__.'/vendor/autoload.php' : __DIR__.'/../../autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);
/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running, we will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/
$kernel->terminate($input, $status);
exit($status);
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="NunoMaduro\Collision\Adapters\Phpunit\Listener"/>
</listeners>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
</phpunit>
<?php
/**
* Sends messages via Serial
*/
namespace Heidilabs;
class SerialDriver
{
protected $port;
protected $baudRate;
protected $serial;
protected $delimiter;
public function __construct($port, $baudRate = 19200, $delimiter = "\n")
{
$this->port = $port;
$this->baudRate = $baudRate;
$this->delimiter = $delimiter;
}
private function getSerial()
{
if ($this->serial == null) {
$serial = new \PhpSerial();
try {
$serial->deviceSet("/dev/ttyUSB0");
$serial->confBaudRate(19200);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
$serial->deviceOpen();
//wait a couple seconds to initialize device
sleep(2);
} catch (\Exception $e) {
throw new SerialException("An error occurred while trying to open the Serial Port $this->port.
Are you sure it's connected?");
}
$this->serial = $serial;
}
return $this->serial;
}
/**
* Commands are 3-letter strings that will be sent along with a payload.
* At the receiving end, you should look for the first 3 characters of the serial input in order to
* identify the command. ex: "MSGthis is the message payload"
* @param $command
* @param $payload
*/
public function sendCommand($command, $payload)
{
$this->getSerial()->sendMessage(strtoupper(substr($command, 0, 3)) . $payload . $this->delimiter);
}
/**
* Sends a simple message / string without prefix
* @param $string
* @throws SerialException
*/
public function sendMessage($string)
{
$this->getSerial()->sendMessage($string . $this->delimiter);
}
public function close()
{
if ($this->serial !== null) {