Coder Social home page Coder Social logo

pi-client's Introduction

Pi Websockets Client

Intro

The idea behind this project is to control devices by physically wiring them to Raspberry Pis. This client is designed to subscribe to a websocket API I built, and respond to events that are broadcast by it.

My current use case is a Raspberry Pi Zero W with pin 11 wired up to the base of a transistor that shorts a normally open push button switch, thus turning something on.

Notes

I'm using this gem for websockets clients. It works well, but doesn't seem to support reconnecting when a connection is lost. My workaround for this is to write the timestamp from each ping to a file (they come every 3 seconds). I then have a separate bash script (check_ping.sh) which runs every minute via cron and checks for the age of the last ping. If the ping is old it'll kill this process and relaunch. Not terribly elegant, but it works well, and makes the client rather robust. Lastly, I set the Pi to restart every night at 3am via cron.

I launch the ruby script on boot via @reboot cron. The check_ping.sh will also start it up, but there will be a longer delay.

Example .env file

HTTP_AUTH_USER=username
HTTP_AUTH_PASS=password
CONTROLLER_URL=localhost:3000
DEVICE_GUID=1234
PLATFORM=PC

These values have to match those set in the API. The device_guid will vary for each device, and is created by the API. PLATFORM=PC is for dev, and turns off all the GPIO pin stuff; set it to PLATFORM=PI for prod.

pi-client's People

Contributors

stephenwetzel avatar

Watchers

johan pretorius avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.