Sensors plugin for CakePHP 4
Installation
You can install this plugin into your CakePHP application using composer., (*1)
The recommended way to install composer packages is:, (*2)
composer config repositories.sensors git https://github.com/sasilen/cakephp-plugin-sensors.git
composer require sasilen/sensors
Configuration
Load required modules with routes, (*3)
./bin/cake plugin load Sasilen/Sensors
Migrate database schema, (*4)
./bin/cake migrations migrate -p Sensors
Add templates (main app)
# /src/View/AppView.php
public function initialize(): void
{
parent::initialize();
$this->loadHelper('CakeDC/Users.AuthLink');
$this->loadHelper('Paginator', ['templates' => 'templates-paginator']);
$this->loadHelper('Form', ['templates' => 'templates-form']);
}
Triggers
If you want to update sensor_id automatically from the sensors list when sensor_value is inserted you can create these two trigger, (*5)
CREATE TRIGGER sensor_values_sensor_id_updater
BEFORE UPDATE ON sensor_values
FOR EACH ROW
SET new.sensor_id = (select id from sensors where name=new.name);
CREATE TRIGGER sensor_values_sensor_id_inserter
BEFORE INSERT ON sensor_values
FOR EACH ROW
SET new.sensor_id = (select id from sensors where name=new.name);
FIX missing:
UPDATE sensor_values SET sensor_values.sensor_id = (SELECT sensors.id FROM sensors WHERE sensors.name = sensor_values.name ) WHERE sensor_values.sensor_id = '';