Skip to main content

Flashlex IOT for python makes it easy to make any python computer an IOT device.

Project description

flashlex-iot-python

the python raspberry pi IOT project for makers

Join the chat at https://gitter.im/flashlex-iot-python/community Build Status

supporting stuff

using python 3

you need the ssl system packages because IOT requires ssl

python3 -m venv venv --system-site-packages
source venv/bin/activate
python3 -m pip install --user --upgrade pip
python3 -m pip install -r requirements.txt
python3
import ssl
print (ssl.OPENSSL_VERSION)
OpenSSL 1.1.0j  20 Nov 2018

installing AWS IOT on the PI

git clone https://github.com/claytantor/flashlex-iot-python.git
cd flashlex-iot-python
sudo python setup.py install

keys

In order to connect a device, you need to download the following a certificate for this thing.

<my-iot-id>.cert.pem
A public key	<my-iot-id>.public.key
A private key	<my-iot-id>.private.key

pub sub

python basicPubSub.py -e <my-iot-endpoint>.iot.us-east-1.amazonaws.com -r ssl/AmazonRootCA1.pem -c ../keys/<my-iot-id>-certificate.pem.crt -k ../keys/<my-iot-id>-private.pem.key

steps

git clone https://github.com/claytantor/flashlex-pi.git
cd flashlex-pi/
pip install virtualenv
/home/pi/.local/bin/virtualenv venv
source venv/bin/activate
pip install -r requirements.txt

creating the systemd service

Instructions for setting up your service can be found at https://www.raspberrypi-spy.co.uk/2015/10/how-to-autorun-a-python-script-on-boot-using-systemd/

sudo cp flashlex.service /lib/systemd/system/flashlex.service
sudo chmod 644 /lib/systemd/system/flashlex.service
sudo systemctl daemon-reload
sudo systemctl enable flashlex.service

add logging to syslog

Then, assuming your distribution is using rsyslog to manage syslogs, create a file in /etc/rsyslog.d/<new_file>.conf with the following content:

if $programname == '<your program identifier>' then /path/to/log/file.log
& stop

restart rsyslog (sudo systemctl restart rsyslog) and enjoy! Your program stdout/stderr will still be available through journalctl (sudo journalctl -u ) but they will also be available in your file of choice.

sudo cp flashlex.conf /etc/rsyslog.d/flashlex.conf
sudo systemctl daemon-reload
sudo systemctl restart flashlex.service
sudo systemctl restart rsyslog

check the status of the service

sudo systemctl status flashlex.service

rotating logs for your service

you will want to rotate logs so your disk doesnt fill up with logs. your conf file for logrotation looks like this in /etc/logrotate.conf:

/var/log/flashlex.log {
    daily
    missingok
    rotate 7
    maxage 7
    dateext
    dateyesterday
}

make a crontab that executes logrotate daily

/usr/sbin/logrotate /etc/logrotate.conf

bootstrap

python -u bootstrap.py -c keys/config-bootstrap.yml -d $(pwd)/data -k $(pwd)/keys

#collect a message

$ source venv/bin/activate
(venv) $ python -u collectmessage.py -c keys/config-bootstrap.yml -d $(pwd)/data -k $(pwd)/keys
starting flashelex app.
collecting message from thing:a44d80ec-bc2d-44d2-8568-eb23f7d44021
https://u100den7gk.execute-api.us-east-1.amazonaws.com/dev/things/a44d80ec-bc2d-44d2-8568-eb23f7d44021/collect {'foo': 'bar'} {'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImE0NGQ4MGVjLWJjMmQtNDRkMi04NTY4LWViMjNmN2Q0NDAyMSJ9.eyJleHAiOjE1NTU3NzU5ODMsIm5iZiI6MTU1NTc3NTg2MywiaXNzIjoidXJuOnRoaW5nOmE0NGQ4MGVjLWJjMmQtNDRkMi04NTY4LWViMjNmN2Q0NDAyMSIsImF1ZCI6InVybjpmbGFzaGxleDphNDRkODBlYy1iYzJkLTQ0ZDItODU2OC1lYjIzZjdkNDQwMjEifQ.Thv2m04Bhgqe5T7KkxGgW0ESvW4gATUhRGedzaTOul820CgQCtXlT158X6T-ysoMqTP5N1du2TF3-tY_zU_QPM-K8uTlkqspIBri72aUurl7nOTKpmlxexHaiJlM3BlkZJBIX0T4bnTraCrrc4BscNQRs7jJcWkW277F-ok59fRRYAVa2nZdZVcrI9ZeGUR3a9BrlO4YslYaldLN61YU-Q-Fg4OK3xEcooPUhNNGfEpL0Gpme3dBI123ADwn10jK8snhIBD76kOeoHy2yCD7lYufclwuXeuvl0xA3QAFdZC-GVaywb9AaNPFg1clbGqmfBkl1hIpUDWK4IodqhZ_Zg', 'Content-Type': 'application/json'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flashlexiot-0.9.12.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

flashlexiot-0.9.12-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file flashlexiot-0.9.12.tar.gz.

File metadata

  • Download URL: flashlexiot-0.9.12.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.10

File hashes

Hashes for flashlexiot-0.9.12.tar.gz
Algorithm Hash digest
SHA256 236cbb3ae0c311c390cb8b51d0c6354645a363ad7fb788e940e62fe739ace5d0
MD5 36dd33b3ab4e521925e137f9880030d0
BLAKE2b-256 0e386ab1ab7a801cb82fdfa283651b96208afe95b2ffbf9e2f427dbbc6d8e52f

See more details on using hashes here.

File details

Details for the file flashlexiot-0.9.12-py3-none-any.whl.

File metadata

  • Download URL: flashlexiot-0.9.12-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.10

File hashes

Hashes for flashlexiot-0.9.12-py3-none-any.whl
Algorithm Hash digest
SHA256 e13c5a7b7fdf14ec32b28e1fd69f68030c30dc60550e79149a0534ee6c09116f
MD5 36725b2a156d600ee22af6e67fd0e1c2
BLAKE2b-256 9fc29c27d7434055474ef359e80967cdf95df1d344a38a23d9f715d4e4ee401a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page