Difference between revisions of "Pi"

From Wiki2
Line 11: Line 11:


{{:ibeacon}}
{{:ibeacon}}
[https://serversforhackers.com/monitoring-processes-with-supervisord forever with supervisord]

Revision as of 09:32, 26 May 2015

default

user pi passwd raspberry

bluetooth 4.0 LE

http://www.ioncannon.net/linux/1570/bluetooth-4-0-le-on-raspberry-pi-with-bluez-5-x/

http://www.elinux.org/RPi_Bluetooth_LE

python

jupyter on python3

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-jupyter-notebook-to-run-ipython-on-ubuntu-16-04


is installed in omen www/environments/jup

tim@omen:/d/fs/www/environments$ pyvenv jup
tim@omen:/d/fs/www$ cd environments/
tim@omen:/d/fs/www/environments$ . jup/bin/activate
(jup) tim@omen:/d/fs/www/environments$ jupyter notebook

(jup) tim@omen:/d/fs/www/environments/jup/bin$ deactivate

accessing object properties

status ={}
status['pond'] = {'spot': 'center', 'state': 'off', 'tleft': 0, 'nexton': 9}
status['pond']['tleft']= 16

parsing u'5'

basic tutorial

https://thenewcircle.com/static/bookshelf/python_fundamentals_tutorial/advanced_types_containers.html

running app forever - supervisorctl

cascada

port = 8087
/home/pi/mypi/cascada/server/cascada.py

cascada2

port = 8088
/home/pi/mypi/cascada/server/cascada2.py

<markdown>

sudo`supervisorctl` reads configuration from `/etc/supervisor/conf.d` and runs whatever files if finds there.

a typical `conf` ile looks like:

   [program:cascada2]
   command=/usr/bin/python /home/pi/mypi/cascada/server/cascada2.py
   directory=/home/pi/mypi/cascada/server
   autostart=true
   autorestart=true
   startretries=3
   stderr_logfile=/var/log/cascada/cascada2.err.log
   stdout_logfile=/var/log/cascada/cascada2.out.log
   user=root
   environment=SECRET_PASSPHRASE='this is secret',SECRET_TWO='another secret'

you may have to `>supervisor reload` then `ctrl c` the `sudo supervisorctl` to get a new program running forever

</markdown>

pi@raspberrypi ~ $ sudo supervisorctl
cascada                          RUNNING    pid 2273, uptime 7 days, 3:17:36


tail -f /var/log/cascada/cascada.out.log
tail -f /var/log/cascada/cascada.err.log

after changing cascada.py

pi@raspberrypi ~ $ sudo supervisorctl
cascada                          RUNNING    pid 2273, uptime 7 days, 3:17:36
supervisor> stop cascada

exit w ctrl C

sudo lsof -i :8087
sudo kill -9 21118 (kill whatever port lsof returns)
pi@raspberrypi ~ $ sudo supervisorctl
cascada                          STOPPED    Jul 16 04:34 PM
supervisor> start cascada
cascada: started
supervisor>

exit w ctrl C ??

  • nohup python app.py &
  • use screen
  • run supervisord(link) on system startup and control all through it (pythonic way :))

nohup means: do not terminate this process even when the stty is cut off.

& at the end means: run this command as a background task.

forever with supervisord

SSE - Server Side Events

http://flask.pocoo.org/snippets/116/

https://github.com/stevenewey/ssedemo


for node

https://www.npmjs.com/package/simple-sse (has room,haven't tried)

https://tomkersten.com/articles/server-sent-events-with-node/

http://www.futureinsights.com/home/real-time-the-easy-way-with-eventsource-angularjs-and-nodejs.html

SocketIO

http://stackoverflow.com/questions/17641602/how-to-emit-to-room-in-socket-io

flask socketio

https://flask-socketio.readthedocs.org/en/latest/

ibeacon

http://www.jaredwolff.com/blog/get-started-with-bluetooth-low-energy/ decribes gattr tool as well

xyfindit

00:eb:19:00:b7:b9,07775dd0111b11e491910800200c9a66,6400,47033,-59,-68

android

https://github.com/alt236/Bluetooth-LE-Library---Android

distance

http://stackoverflow.com/questions/20416218/understanding-ibeacon-distancing

http://en.wikipedia.org/wiki/DBm

The iBeacon output power is measured (calibrated) at a distance of 1 meter. Let's suppose that this is -59 dBm (just an example). The iBeacon will include this number as part of its LE advertisment.

The listening device (iPhone, etc), will measure the RSSI of the device. Let's suppose, for example, that this is, say, -72 dBm.

Since these numbers are in dBm, the ratio of the power is actually the difference in dB. So:

ratio_dB = txCalibratedPower - RSSI To convert that into a linear ratio, we use the standard formula for dB:

ratio_linear = 10 ^ (ratio_dB / 10) If we assume conservation of energy, then the signal strength must fall off as 1/r^2. So:

power = power_at_1_meter / r^2. Solving for r, we get:

r = sqrt(ratio_linear) In Javascript, the code would look like this:

function getRange(txCalibratedPower, rssi) {

   var ratio_db = txCalibratedPower - rssi;
   var ratio_linear = Math.pow(10, ratio_db / 10);
   var r = Math.sqrt(ratio_linear);
   return r;

} Note, that, if you're inside a steel building, then perhaps there will be internal reflections that make the signal decay slower than 1/r^2. If the signal passes through a human body (water) then the signal will be attenuated. It's very likely that the antenna doesn't have equal gain in all directions. Metal objects in the room may create strange interference patterns. Etc, etc... YMMV.

shareeditflag edited Feb 7 '14 at 2:19

answered Feb 7 '14 at 1:24

Mark Fassler 43135

http://stackoverflow.com/questions/15687332/bluetooth-le-rssi-for-proximity-detection-ios

estimote

Hi Wojtek,

Yep I got them and they are an exciting technology. But I must live in a 2.4 ghz jungle. That and the interesting variability you get between dog lying down, standing up and walking around can alter their signal markedly. Add to that the changes to the signal as I move about the house with my phone and you have a real puzzle.

I have better luck fixing by fixing my bluetooth receiver(s) and not detecting the beacons from mobile devices.

So I have set up raspberry pi's at key points in the yard to track the beacons. Using the libraries Bluez and Bluepy. I am able to estimate distance using the dB difference between the RSSI and the dB at 1 meter to get a power ratio that varies with the square of the distance. It is still cranky but once I put a few pi's in the yard I'll have boatloads of data to play around with.

It will be interesting to try out some filters, maybe put the data through a Hidden Markov Model or train up a neural network.

I have got some other beacons from other manufacturers and they all have similar variability. What would keep my concentration on Estimotes would be a bit of information on the Unknown Services that show up on scans. In particular, you advertise your beacons as standing out with capabilities like the accelerometer on board. How do I read that?

Meanwhile, the pi's are running a little restful API and some socket.io to communicate with my mobile devices and laptops. I'll have a mobile friendly responsive design HTML5/javascript app running soon. If I was doing dedicated I'd start on Android before IOS.

Thanks for your offer of help. Good luck with your product. The potential is enormous.

forever with supervisord