Pi Zero Easy IoT

安価で簡単に IoT を始めよう! - Raspberry Pi Zero によるプログラミングレス IoT 環境データ収集

pizero-workshop for developers

Overview

pizero-workshop provides the programs that setup Iot tools from Raspberry Pi Zero with begginer friendly configuration.

If you edit some configuration files on microSD card (installed Raspbian Buster and this programs) /boot/ area (here is able to read and write by using Windows or MacOS), and insert the microSD card into Raspberry Pi Zero and power on it with sensors, you can get sensing, and saving the data as csv, and uploading to a cloud services. And you can reset a configuration by editting files without user login to Raspbian Buster.

Installation

pizero-workshop is can be installed in Raspbian Buster.

For showing command options, execute following.

cd pizero-workshop;
sudo ./install

And install step by step.

sudo ./install -installFirst
sudo ./install -installNode
sudo ./install -installNpmPackages
sudo ./install -installAptPackages
sudo ./install -installFiles

Configuration

There are 4 configuration files in pizero-workshop.

Main programs

Main programs task is sensing, and saving the csv to local, and uploading to the cloud services. Followings is a configuration format of config.js for main programs (this configuration file is imported to pizero-workshop.js)

config.js
//exports array of settings objects
module.exports = [

  //first setting
  {
    intervalMillisec: 60000,    //sensing and record interval (milli second)

    //have to filled belows to sensing
    omron2jcieBu01Name: "Rbt", //maybe fix "Rbt"
    omron2jcieBu01Address: "", //12 charactors of number or aphabet (like "A1B2C3D4E5F6")

    //if filled below, saving csv file 
    csvFilename: "",           //csv file name for saving sensing data. if value is "", not saving. Available charactors in filename are except '/' and X00 (null). 

    //if filled belows, uploading to Machinist
    machinistApiKey: "",       //from Machinist acount. if value is "", uploading to Machinst is disable.
    machinistAgent: "",        //from Machinist acount. if value is "", uploading to Machinst is disable.
    machinistBatchQuantity: 1, //number of temporary stock the sensing data before sending

    //if filled belows, uploading to Ambient
    ambientChannelId: "",      //from Ambient acount. if value is "", uploading to Ambient is disable.
    ambientWriteKey: "",       //from Ambient acount. if value is "", uploading to Ambient is disable.
    ambientBatchQuantity: 1    //number of temporary stock the sensing data before sending
  }
 
  //,
  //... more objects like first one
];

After making above configuration, you can test main programs by executing following commands.

cd pizero-workshop
sudo npm start

And test start service (systemd).

sudo systemctl start pizero-workshop

Custom configuration for syncLog

/boot/setting/syncLogConfig.js
/*
This is syncLog setting file (Javascript source).
Setting is array of objects. 
Followings are example of setting.

module.exports = [
  {
    type: 'rsync',                           //rsync
    intervalHours: 1,                        //execute interval hours
    source: '/home/pi/source_dir/',          //local source directory
    dest: '/boot/data/'                      //local distination directory
  }
  ,
  {
    type: 'rclone',                          //rclone
    intervalHours: 24,                       //execute interval hours
    rcloneConf: '/boot/rclone.conf',         //configuration file generated by rclone
    source: '/boot/data',                    //local directory
    destService: 'gdrive',                   //service name in rclone.conf
    destDir: 'data'                          //folder in cloud service
  }
];
*/

module.exports = [
  {
    type: 'rsync',
    intervalHours: 1,                         // please change 
    source: '/home/pi/pizero-workshop/log/',  // fix this for pizero-workshop programs
    dest: '/boot/setting/log/'                // fix this for pizero-workshop programs
  }
  ,
  {
    type: 'rclone',
    intervalHours: 1,                         // please change 
    rcloneConf: '/boot/setting/rclone.conf',  // fix this for pizero-workshop programs
    source: '/boot/setting/log',              // fix this for pizero-workshop programs
    destService: 'gdrive',                    // please change 
    destDir: 'pizero-workshop'                // please change
  }
];

How to work

pizero-workshop has main system programs (starter and sensing and recordings), and contained additional 3 supporting systems (systemd service), bootPi, bootWifi, syncLog.

Instructions of bootPi and bootWifi are in each above links, because it's enough to setup in general. And instructions of main system and syncLog are followings.

Files installed and generated

Followings are installed files (when execute ./install), and generated files (when system works).

system files
/etc/systemd/system/pizero-workshop.service  (systemd service definition)
/boot/setting/logrotate                      (logrotate configuration)
/boot/setting/cron                           (cromtab file)
specific configuration files
/boot/setting/config.js          (configuration file for pizero-workshop.js)
setting/config.js                (configuration file for pizero-workshop.js, if not exist main file, use this file)

/boot/setting/bootPi.conf        (configuration file for bootPi.service)
/boot/setting/bootWifiConfig.js  (configuration file for bootWifi.service)
/boot/setting/syncLogConfig.js   (configuration file for syncLog.service)
/boot/setting/rclone.conf        (configuration file for syncLog.service)
output files (data, status, log, ...)
log/xxx.csv                      (will be created and added by main programs ,and syncLog.service will copy this to google drive)
log/error.txt                    (will be created and added by pizero-workshop.service, bootWifi.service, bootPi.service, and syncLog.service)

/boot/setting/log/xxx.csv        (rsync from log/xxx.csv by syncLog.service)
/boot/setting/log/error.txt      (and rsync from log/error.txt by syncLog.service)

/boot/setting/starterStatus.txt  (redirected ./starter.sh output by cron, redirected systemctl start bootPi, bootWifi, syncLog output by cron)  
/boot/setting/bootPiStatus.txt   (redirected bootPi/bootPi.sh output by bootPi.service)  
/boot/setting/bootWifiStatus.txt (redirected bootWifi/bootWifi.sh output by bootWifi.service)  
/boot/setting/syncLogStatus.txt  (redirected syncLog/start.sh output by syncLog.service)  
call graph and relations (only main system programs)
/etc/cron.d/pizero-workshop --symbolic link--> /boot/setting/cron
/etc/logrotate.d/pizero-workshop --symbolic link--> /boot/setting/logrotate

/boot/setting/cron @boot --execute--> starter.sh

starter.sh --execute--> check.js
           --execute--> systemctl start pizero-workshop.service

pizero-workshop.service --ExecStart--> npm start

npm start --execute--> pizero-workshop.js

pizero-workshop.js --call--> /boot/setting/config.js or setting/config.js, 
                             lib/omron2jciebu01.js, lib/csv.js, lib/machinist.js, lib/ambient.js, lib/pattern.js

Libraries in lib/ , sensors, records, patterns

pizero-workshop.js calls a sensors, records, and patterns libraries in lib/ .