RaspberryPi wifi networking, programming and hardware IO

As part of a small project to do energy and environmental monitoring of our home I have been getting to grips with some RaspberryPi hardware that I purchased perhaps 3 years ago. A few challenges came up! I’ll cover a few in a couple of posts. Getting a wifi dongle… Continue reading

Yii2 Rbac – Role based authorization

I’m using Yii2-User as my authentication framework and I’ve used Yii2’s standard database rooted  authorisation scheme. As usual there are a few gotcha’s that need explaining. When configuring rbac in the components section of the config file this is usually suggested. ‘authManager’ => [ ‘class’ => ‘yii\rbac\DbManager’, ‘defaultRoles’ => [‘guest’], ],… Continue reading

Yii2 Authorization

Yii2 provides a  Role Based Authorization Control ( rbac ) module off the shelf. The code at /vendor/yiisoft/yii2/rbac under your basic application folder is what we are dealing with here. Unfortunately it requires initialization and the tables need building before it can actually be used. The documentation around this process is a little… Continue reading

Yii2 Migrations

Why oh why is the standard of Yii2 documentation apparently so universally poor?

While trying to look into getting migrations going on my Yii development site I stumbled over a web page that appeared to lay things out pretty well. I should have guessed that life was not going to be that simple! This …

First we need to create a migration:
 
yii create/migration insert_user

.. rapidly turned into an in depth investigation of the migration system. Try it yourself, the above command fails in at least two different ways.

First things first, what do migrations do in Yii?  ‘Migration provides a set of convenient methods for manipulating database data and schema. For example, the insert() method can be used to easily insert a row of data into a database table; the createTable() method can be used to create a database table. Compared with the same methods in yii\db\Command, these methods will display extra information showing the method parameters and execution time, which may be useful when applying migrations.’

That comes from the Yii2 Documentation so at least there’s a start. When it is used with the command line it gives us a way to execute upgrade ( or downgrade ) code while inside the environment of our website.

We can use a Yii command to generate a framework migration file as follows.

Dream up a label for your migration and in the root directory of your Yii2 application issue the following command.

*> php yii migrate/create \migration_label/

The command responds with a prompt asking you to accept the generation of a new migration file. You’ll notice that the filename has some additional information concatenated in to it. Basically a time and date and key. These are used to track your use of migrations.

Some Gotcha’s and notes here.

  1. Migrations and other console commands use the console.php configuration. I spent a frustrating hour or three trying to work out why component configurations that I copied from the internet were apparently not working. I’d put them into web.php and not into console.php!
  2. When a migration file is run and it completes without error and entry is made into the table ‘migrations’ in your database along with a timestamp. If you are testing a migration subsequent edits of the migration file are not applied since the tool does not know that the file has changed. You need to either rename the file or simply drop the relative entry to the migration table before rerunning the migration.

While you are in your root directory issue the following command.

*> php yii help migrate

You’ll see some additional commands that give some more insight into the migrate system.

Next I’ll use a practical example of generating a migration to help with the installation of the Yii2 Authorization module to expand on how things work.

LED’s

Light Emitting Diodes or LED’s are rapidly becoming the preferred option for fitting in applications where low current and a long life are beneficial. Obviously on a yacht where power is supplied from batteries for some or all of the time, reducing the current draw delivers a lot of benefits. Longer battery duration so longer between charges for example. The added benefit of very long lifetimes is another drawcard.

There are some pitfalls however and the consumer is not helped by the lack of a common knowledge base. This post is an attempt to throw some light ( sorry 🙂 ) on the whole subject.

1 – Led’s are polarity sensitive
2 – led’s are current driven devices …. Not voltage driven!