Giter Site home page Giter Site logo

epicureanheron / onionweatheroled Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 4 KB

Display current weather in Minneapolis on the Onion Omega's OLED screen using node.js

JavaScript 100.00%
omega2 onion onion-omega2 weather weather-api minneapolis crontab cron nodejs

onionweatheroled's Introduction

Required Equipment

  • Onion Omega2
  • Onion Expansion Dock
  • OLED Expansion
  • USB

Set Up

Configured Onion to boot from USB (may not be necessary) but absolutely most utilize the space on the USB. Ran into trouble with node and npm otherwise. To do so, follow this guide:

Booting from External Storage

Then installed node and npm by following this guide:

Installing and Using NodeJS

Ultimately, run the following:

opkg update
opkg install nodejs

Created the directory "weatheroled" on the file path /mnt/sda. So the full directory name is now

/mnt/sda/weatheroled

Navigate to that directory and create the file which will be gathering weather data and writing to the OLED screen.

touch index.js

and initialize the directory with npm

npm init

There is a node package specifically for interacting with the Onion OLED screen. Here is the guide and documentation: OLED Expansion Node Module

To install the module run

opkg update
opkg install node-oled-exp

index.js

Leveraging the "https" module and the API from Open Weather Map, data is taken by passing the lat and long of Minneapolis.

That returns a JSON object.

From there, the code parses the data and grabs the weather, temp, sunrise, and sunset. The sunrise and sunset are values in unix time which have to be parsed.

The data is then displayed on the OLED screen

Cron

Once index.js is set up, cron can be leveraged to run the script on a schedule.

Onion's documentation on crontab is helpful for setting up a cron job:

Running a Command on a Schedule

Run

crontab -e

Update that file with (this will run the script every 15 minutes)

*/15 * * * * /usr/bin/node /mnt/sda/weatheroled/index.js

exit crontab using vi

[esc] :wq [enter]

check to see the changes were made

crontab -l

Reset cron

/etc/init.d/cron restart

Issues

  • request module

    Ideally the request module would have been used rather than the https module. However, installing request via npm like so

    npm i request
    

    caused the Onion to freeze up. The package and its dependencies are unable to be downloaded for some reason

  • API Key

    Currently the APIKey is written into the file itself, ideally node would handle this information

  • Sunrise/Sunset data

    The current converted unix time displays the day of the week, day, and time. The day and date are not necessary. These also take up a lot of space on the OLED screen, so it could be parsed down to be just the hour and minute of each event.

onionweatheroled's People

Contributors

epicureanheron avatar

Stargazers

 avatar

Watchers

 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.