MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. SJK
    3. Best
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    S
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 3
    • Groups 0

    Posts

    Recent Best Controversial
    • Little magic mirror (but not a mirror)

      Used an old kindle to display the info.

      I’ve got a Raspberry Pi that creates the magic mirror info and saves it as an image file, the kindle just downloads and displays the image every 5 minutes. Seems to work well so far.

      Phot.jpeg

      posted in Show your Mirror
      S
      SJK
    • RE: Little magic mirror (but not a mirror)

      @djgigabit Here is my (sanatized) version of the index.js file from the web-to-kindle:

      const express = require('express');
      const path = require('path');
      const puppeteer = require('puppeteer');
      const execFile = require('child_process').execFile;
      const fs = require('fs');
      
      const PORT = process.env.PORT || 3000;
      
      express()
        .use(express.static(path.join(__dirname, 'public')))
        .set('views', path.join(__dirname, 'views'))
        .set('view engine', 'ejs')
        .get('/', async (req, res) => {
          const browser = await puppeteer.launch({ 
              executablePath: '/bin/chromium-browser'
              });
          const page = await browser.newPage();
          await page.setViewport({ width: 600, height: 800 });
          await page.goto(process.env.SCREENSHOT_URL || '<web address of magicmirror>');
      
          await new Promise(r => setTimeout(r, 3000));
      
          await page.screenshot({
            path: '/home/<user>/screenshot.png',
          });
      
          await browser.close();
      
          await convert('/home/<user>/screenshot.png');
          screenshot = fs.readFileSync('/home/<user>/screenshot.png');
      
          res.writeHead(200, {
            'Content-Type': 'image/png',
            'Content-Length': screenshot.length,
          });
          return res.end(screenshot);
        })
        .listen(PORT, () => console.log(`Listening on ${PORT}`));
      
      
      function convert(filename) {
        return new Promise((resolve, reject) => {
          const args = [filename, '-gravity', 'center', '-negate', '-extent', '600x800', '-colorspace', 'gray', '-depth', '6', '-alpha', 'remove', '-level', '50x100%', filename];
          execFile('convert', args, (error, stdout, stderr) => {
            if (error) {
              console.error({ error, stdout, stderr });
              reject();
            } else {
              resolve();
            }
          });
        });
      }
      

      This is where I added the pause before it captures the screenshot. I also had to change the puppeteer.launch command as it was not a happy bunny running on a headerless server.

      posted in Show your Mirror
      S
      SJK
    • 1 / 1