Sphero BOLT on RPi

igbopie/spherov2.js

git clone into /home/pi

cd spherov2.js

npm install

cd node_modules/@abandonware/bluetooth-hci-socket

nvm use 10

npm install –update-binary

In your code:

const {Svanner, Utils, SpheroBolt} = require(‘/home/pi/spherov2.js/node_modules/spherov2.js’)

sudo npm install -g typescript

sudo npm install -g ts-node

cd ~/.node-red/node_modules

ln -s /home/pi/node_modules/@abandonware/noble .

cd ~/spherov2js/@abandonware/bluetooth-hci-socket

npm install –update-binary

I should change the .ts files in spherov2.js src directory, but edited directly in ~/spherov2.js/node_modules/spherov2.js/dist

http://www.jemfr.com/pagess/how-to-install-nvm-and-node-js-on-raspberry-pi

chrkhl/sphero-connector-http – i couldn’t get working but a good basis for my HTTP wrapper

awesomeopensource.com – search for sphero

Wrong yarn

sudo apt remove cmd-test

sudo apr autoremove

sudo npm install -g yarn OR was it pip3 install yarn?

igbopie/spherov2.js

http://wiki.mark-toma.com/view/Sphero_API_Tutorial

https://query1.finance.yahoo.com/v11/finance/quoteSummary/HSBC?modules=financialData

https://www.insplay.eu/en_US/slides/slide/sphero-bolt-javascript-coding-115

Running Server

node /usr/lib/node_modules/node-red/red.js

cd /home/pi/sphero2.js && sudo node index.js

Install docker on Node-Red

https://phoenixnap.com/kb/docker-on-raspberry-pi

sudo docker run -p 1881:1880 -v /home/pi/nodered-docker/data1:/data –rm –name mynodered1 –security-opt=seccomp=unconfined nodered/node-red:latest

https://github.com/node-red/node-red-docker/issues/319

Create alias for each docker nodered – see https://piwithvic.com/raspberry-pi/terminal/shell-commands/alias

vi /home /pi/.bash_aliases

alias nr1=’sudo docker run -p 1881:1880 -v /home/pi/nodered-docker/data1:/data –rm –name mynodered1 –security-opt=seccomp=unconfined nodered/node-red:latest’
alias nr2=’sudo docker run -p 1882:1880 -v /home/pi/nodered-docker/data2:/data –rm –name mynodered2 –security-opt=seccomp=unconfined nodered/node-red:latest’
alias nr3=’sudo docker run -p 1883:1880 -v /home/pi/nodered-docker/data3:/data –rm –name mynodered3 –security-opt=seccomp=unconfined nodered/node-red:latest’
alias nr4=’sudo docker run -p 1884:1880 -v /home/pi/nodered-docker/data4:/data –rm –name mynodered4 –security-opt=seccomp=unconfined nodered/node-red:latest’
alias nr5=’sudo docker run -p 1885:1880 -v /home/pi/nodered-docker/data5:/data –rm –name mynodered5 –security-opt=seccomp=unconfined nodered/node-red:latest’
alias nr6=’sudo docker run -p 1886:1880 -v /home/pi/nodered-docker/data6:/data –rm –name mynodered6 –security-opt=seccomp=unconfined nodered/node-red:latest’
alias nr7=’sudo docker run -p 1887:1880 -v /home/pi/nodered-docker/data7:/data –rm –name mynodered7 –security-opt=seccomp=unconfined nodered/node-red:latest’
alias nr8=’sudo docker run -p 1888:1880 -v /home/pi/nodered-docker/data8:/data –rm –name mynodered8 –security-opt=seccomp=unconfined nodered/node-red:latest’

View OAS spec

nvm use 14

npm install -g http-server

cd /home/pi/spherov2.js

http-server

browse http://localhost:8080/index.html

Mac Time Machine to Synology Backup Problems

log show –predicate ‘subsystem == “com.apple.TimeMachine”‘ –info | grep ‘upd: (‘ | cut -c 1-19,140-999

sudo log stream –predicate ‘subsystem==”com.apple.TimeMachine”‘ –info

In the end I had to move the sparse bundle on the target time machine NAS to kick off a new backup. Nothing else would work.

Python script for Christmas Star

from star import Star
from time import sleep
from gpiozero.tools import random_values
from signal import pause

star = Star(pwm=True)

step = 0.5
count = 0

try:
    leds = star.leds
    while True:
        for x in range(5):
            star.outer.off()
            star.inner.off()
            for led in leds:
                led.pulse()
                sleep(.2)

        for x in range(1):
            star.outer.off()
            star.inner.off()
            while True:
               if(count%26!=0):
                   leds[count%26].on()
                   sleep(step)
                   leds[count%26].off()

               count += 1
               step = step*0.99

               if(step <= 0.0001):
                   count = 0
                   step = 2
                   break

        for x in range(5):
            star.inner.on()
            star.outer.off()
            sleep(.5)
            star.toggle()
            sleep(.5)
except KeyboardInterrupt:
    star.off()
    star.close()

Automated scripts on RPi

This is a useful guide to using systemd: https://www.thedigitalpictureframe.com/ultimate-guide-systemd-autostart-scripts-raspberry-pi/

[Unit]
Description=lights Service
After=multi-user.target

[Service]
Type=idle
ExecStart=/usr/bin/python3 neopixel_mqtt.py settings.yaml
WorkingDirectory=/home/pi/neopixel_mqtt/src
User=root
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
sudo vi /lib/systemd/system/lights.service
sudo systemctl daemon-reload
systemctl status lights.service
sudo systemctl enable lights.service

System Info integrated with Home Assistant

I looked at Glances https://github.com/nicolargo/glances/blob/master/README.rst and while it’s good for CPU, memory and Disk it doesn’t show temperature, IP, OS etc… by default. Also seems to take a lot of CPU on Pi-zero.

Should the data be push or pull?

For push, we have a program running on the remote server that pushes info for MQTT.

For pull, we host an API on the remote server that a central controller polls.

PatternProsCons
PushPush can be scheduled so don’t have to worry about constantly running a server.Refresh rate set by server.
Load could be affected by program starting to push events.
PullRefresh rate set by client.
Find quickly if server is healthy.
Have to run API on remote server continually – needs auto restart.

On balance, because some servers (e.g. rpi-zero) get more impacted by always on API server, recommend going for push method.

Initially I used a python script from https://github.com/Sennevds/system_sensors.git but I had problems when it crashed.

So I’ve modified the script so that it dies after publishing the MQTT topics, so it can be scheduled in crontab at whatever frequency you like. Here’s the repo: https://gitlab.com/hyperons/system_sensors

Home Assistant custom UI

Vertical Stack in card

/local/community/vertical-stack-in-card/vertical-stack-in-card.js

JavaScript Module

type: 'custom:vertical-stack-in-card'
title: My Card
cards:
 - type: glance 
   entities: 
     - sensor.office_temperature
 - type: entities 
   entities: 
     - switch.lava_lamp 

Mini Graph Card

/local/community/mini-graph-card/mini-graph-card-bundle.js

JavaScript Module

type: 'custom:mini-graph-card'
entities:
 - sensor.office_temperature
 - sensor.office_humidity 

Slider Entity Row

/local/community/lovelace-slider-entity-row/slider-entity-row.js

JavaScript Module

type: entities
entities:
 - light.office_2
 - type: 'custom:slider-entity-row'
   entity: light.office_2 

Remote shutdown

ssh is great for remote shutdown, but running from docker and managing the key exchange can be a pain.

I’m now trying a simple python script (got idea from https://www.raspberrypi.org/forums/viewtopic.php?t=256919) that I can use to shutdown and get status.

#!/usr/bin/python2 
import BaseHTTPServer 
import os 

class HttpHandler(BaseHTTPServer.BaseHTTPRequestHandler):
   def do_GET(self):
     self.send_response(200)
     self.send_header("Content-type", "text/html")
     self.end_headers()
     if self.path == "/shutdown":
       self.wfile.write("Shutting Down")
       os.popen("sudo shutdown -h now")
     elif self.path == "/status":
       self.wfile.write("OK")
     else:
       self.wfile.write("Ignored") 
BaseHTTPServer.HTTPServer(("", 8089), HttpHandler).serve_forever()

To get this script run at boot, follow instructions here https://www.tomshardware.com/uk/how-to/run-script-at-boot-raspberry-pi

Basically add in crontab:

@reboot python2 /home/pi/handler.py

OctoPi Setup

Setup Chromium

cp /etc/xdg/lxsession/LXDE-pi/autostart /home/pi/.config/lxsession/LXDE-pi/autostart
vi autostart
@chromium --start-fullscreen http://localhost/

Setup Backup

sudo apt-get install piclone
https://www.raspberrypi.org/blog/another-update-raspbian/

 

Start second camera

vi ~/.octoprint/config.yaml

system: actions: – action: streamon command: /root/bin/webcam2d confirm: false name: Start 2nd camera

 

Setup new temperature probes

Connect Multiple Temperature Sensors with Raspberry Pi

Restart OctoPrint

sudo service octoprint restart

Stop VNC

sudo systemctl stop vncserver-x11-serviced.service

Create your own website, free on WordPress.com.Create your own website.
Start free