Skip to content

Send messages to family or loved ones with an Inky pHAT and Raspberry Pi Zero W

Notifications You must be signed in to change notification settings

corey-schneider/inky-phat-messenger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inky Messenger

Send messages (and show hourly weather) to family or loved ones

Image of working display

Like the case? Get it from balenalabs' inkyshot repo

Have questions? Feel free to open a new discussion in this repo

Table of Contents


Features

  • Send an email ... text message ... Discord message to update the message on the inky phat
  • Weather status icon
  • Temperature (in Fahrenheit) from OpenWeatherMap API (RIP DarkSky)
  • Date in the bottom right corner
  • Can send a message up to 4 lines long
  • Makes one call to the IpInfo API (unless the device is moved to a different network)
  • Logging of errors saved in log.txt for easy debugging though sftp if the device suddenly stops working
    • Log will include:
      • Incorrect / invalid email credentials
      • Incorrect / invalid API key
      • Missing email or password in config.json
      • Missing API key in config.json
      • Missing config.json
  • Discord commands:
    • !reboot - Restarts the Raspberry Pi
    • !shutdown - Turns off the Raspberry Pi
    • any text here - Sends a message. Usage: Hello! will show Hello! on the display

Hardware

Setup

1. Setting up the Pi

  • Download Raspberry Pi OS Lite
  • Flash image to SD card with Raspberry Pi imager. While this is happening...
  • Safely remove and reinsert the microSD card you just flashed
  • Put YOUR modified version of wpa_supplicant.conf and ssh directly onto the root directory of the microSD card
  • Insert microSD, boot up the Pi, and SSH into it
  • Download the necessary files through curl https://get.pimoroni.com/inky | bash
  • Enable SPI and I2C. To do this, run sudo raspi-config, scroll to Interface Options, and enable them.
    • While in raspi-config, change the time zone (unless you live in the UK). Select Localisation Options > Timezone.
  • Run sudo apt-get update and sudo apt-get upgrade - This will take a while
  • Run python3 -m pip install --upgrade pip and python3 -m pip install --upgrade Pillow and python3 -m pip install discord
  • Run cd ~ and git clone https://github.com/corey-schneider/inky-phat-messenger.git and cd inky-phat-messenger

2. Setting up OpenWeatherMap and Discord

  • Create a new (free) account with OpenWeatherMap.org.
    • Sign in, click your name in the top right, click My API keys and copy the Key to config/config.json
  • Create Discord bot:
    • Create a Discord account or sign in to your existing account
    • Create a new server, name it whatever you'd like
      • You may want to create a server icon - there is a Raspberry Pi icon that can be found here
    • Head to https://discord.com/developers/applications
    • Click New Application in the top right and name it inky (or whatever you'd like)
    • Click Bot on the left column and then Reset Token on the right
    • Copy your TOKEN and be sure not to share it with anyone. Paste it in config/config.json under discord > token
      • You may also enter your discord handle there too. Be sure to include your hash tag and numbers. This will act as a whitelist, only messages from discord > allowed_user will change the message on the inky phat, but you may also leave it blank to allow anyone in the server to change the message
    • Still in the Bot section, scroll down to the Privileged Gateway Intents section. Enable the following 3 toggles:
      • PRESENCE INTENT
      • SERVER MEMBERS INTENT
      • MESSAGE CONTENT INTENT
    • Click OAuth2 in the left column. Select the dropdown URL Generator, check bot under the SCOPES section. Under BOT PERMISSIONS, check Send Messages, Manage Messages, Read Message History
    • You should now see a link at the bottom of SCOPES ending with &scope=bot - visit this link. It should ask which server you'd like to attach the bot to - select the server made in the 2nd step

3. Final touches

  • After testing to make sure everything is working, we need to make sure discordbot.py runs on startup and display.py runs every hour to update the weather
    • Run crontab -e. Type 1 if prompted to select an editor
    • At the bottom of the file, enter these two lines:
      • @reboot sleep 30; cd /home/pi/inky-phat-messenger && python3 /home/pi/inky-phat-messenger/discordbot.py
      • @hourly cd /home/pi/inky-phat-messenger && python3 /home/pi/inky-phat-messenger/display.py
    • hit ctrl o, enter, then ctrl x

That's it!

If you need help, feel free to open a new discussion in this repo.

Troubleshooting

  • If you see an error saying File "/home/pi/.local/lib/python3.7/site-packages/PIL/Image.py", line 109, in <module> or something about from . import _imaging as core...
    • Run sudo rm -rf /home/pi/.local/lib/python3.7/site-packages/PIL/. If the error persists, notice the directory - you may see python3.8 or similar - change the rm -rf command to the version seen in your error.
  • If the Discord bot is showing as offline on the Discord server...
    • Check the connection of the raspberry pi - make sure you can ssh into it
    • Make sure the token is correct and placed in config/config.json
    • Check the log.txt for an error message from discordbot
  • If the Discord bot is not responding, the bot is likely offline and needs to be restarted
  • If the Discord bot is saying you're not authorized, make sure you entered your name correctly in config/config.json. It should look similar to this: "allowed_user": "tester#1234". Reminder that this is NOT the bot's name; it is YOUR personal account's name

TODO

  • Use PIL to create a mockup image of the display and have the bot send it over Discord
  • Clean up code in display.py
    • Separate code into methods and classes
      • Weather can be its own class
    • Integrate bottom_frame_info better
      • If false, move text lower or allow for longer messages
    • Vertical align text
    • Remove print alongside logger
    • Change sys.exit(message) to (0)
  • Fix logger
    • Should print
  • Add more commands to Discord bot
    • font size
    • font style
    • get IP / location / weather information
    • enable / disable bottom frame
    • !help command to show all commands
  • Have error messages routed to Discord bot
  • Set up optional alerts to recipient on Discord bot
    • Enter the recipient's Discord handle and alert them when a new message arrives on the inky display
  • Add more weather icons
    • Hopefully remove the ugly bump too
    • Climacons are really nice
  • Finer detailed weather
  • Have discord bot be aware of length of message and reject a message that will overflow off the screen
  • paragraph = textwrap.wrap(message, width=24) 24 cuts off, may need to lower to 23 - do some testing
  • Create method for saving to json
    • "Send your first message via discord" doesn't save to configuration file
  • Add automatic wifi and automate the setup

Credits

🍻

0xbb5f5d978acbde2ec79736cc5398768a35665d42

Ethereum: 0xbb5f5d978acbde2ec79736cc5398768a35665d42