Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions config/model/appConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ class AppConfig:
timestampFormat: str
imageWidth: int
imageHeight: int
collectors: list[str] = field(default_factory=list, init=True)
destinationFolder: str
collectors: list[str] = field(default_factory=list, init=True)
3 changes: 1 addition & 2 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"timestampFormat": "%Y.%m.%d %H:%M:%S",
"imageWidth": 1200,
"imageHeight": 825,
"collectors": ["GoogleKeepCollector", "TrelloCollector"],
"destinationFolder": "YOUR_DESTINATION_FOLDER"
"collectors": ["GoogleKeepCollector", "TrelloCollector"]
}
35 changes: 31 additions & 4 deletions inkplate/inkplate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "Inkplate.h"
#include <WiFi.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
Expand All @@ -26,7 +27,8 @@ Inkplate display(INKPLATE_3BIT);

const char ssid[] = "YOUR WIFI SSID"; // Your WiFi SSID
const char *password = "YOUR WIFI PASSWORD"; // Your WiFi password
const char *imgurl = "http://url.to.your.server/inkcheck.png"; // Your dashboard image web address
const char *generateurl = "http://<INKCHECK IP>:8080/generate"; // Your InkCheck generate endpoint
const char *imgurl = "http://<INKCHECK IP>:8080/image"; // Your InkCheck image endpoint

// Initialize Telegram BOT
#define BOTtoken "YOUR TELEGRAM BOT TOKEN" // your Bot Token (Get from Botfather)
Expand All @@ -50,10 +52,35 @@ void setup()
display.begin();

// Join wifi, retrieve image, update display
display.joinAP(ssid, password);
int joinAPresult = display.joinAP(ssid, password);
if(joinAPresult == 1) {
Serial.println("Joined the AP.");
} else {
Serial.println("Error joining the AP. Error code: " + success);
}

// Trigger image generation
Serial.println("Getting InkCheck image.");
HTTPClient http;
http.begin(generateurl);
if (http.GET() > 0) {
Serial.println(http.getString());
}

// Sleep for a minute until the image generation
Serial.println("Going to sleep for a minute.");
delay(60000);

// Get the image
char url[256];
strcpy(url, imgurl);
Serial.println(display.drawImage(url, display.PNG, 0, 0));
int drawResult = display.drawImage(url, display.PNG, 0, 0);
if (drawResult == 1) {
Serial.println("Image updated.");
} else {
Serial.println("Error drawing image. Error code: " + drawResult);
}

display.display();

//uncomment or delete the following section if not using Telegram to send message when battery is low
Expand Down Expand Up @@ -89,4 +116,4 @@ int calc_battery_percentage(double battv)
battery_percentage = 100;

return battery_percentage;
}
}
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def generate():
data_list.append(collector.get_data())

renderer = Renderer(app_config.imageWidth, app_config.imageHeight)
renderer.render(timestamp, data_list, app_config.destinationFolder)
renderer.render(timestamp, data_list)

response = 'Inkcheck image is updated.'
logger.info(response)
Expand Down
12 changes: 0 additions & 12 deletions postman/InkCheck.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,5 @@
]
}
}
],
"variable": [
{
"key": "host",
"value": "http://localhost",
"type": "string"
},
{
"key": "port",
"value": "8080",
"type": "string"
}
]
}
21 changes: 21 additions & 0 deletions postman/Inkcheck.postman_environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"id": "a4feb904-af9f-4ef5-93f7-2843ed94e1c8",
"name": "Inkcheck",
"values": [
{
"key": "host",
"value": "http://localhost",
"type": "default",
"enabled": true
},
{
"key": "port",
"value": "8080",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2023-11-27T20:01:21.210Z",
"_postman_exported_using": "Postman/10.20.3"
}
47 changes: 29 additions & 18 deletions renderer/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"""

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from time import sleep
from jinja2 import Environment, FileSystemLoader
from selenium.webdriver.common.by import By
from logger.logger import logger
import pathlib
import shutil
import sys
import os

class Renderer:
Expand All @@ -23,6 +23,9 @@ def __init__(self, width, height):
self.output_html = 'inkcheck.html'
self.curr_path = str(pathlib.Path(__file__).parent.absolute())
self.project_path = os.path.abspath(os.curdir)

logger.info(f"On platform: {sys.platform}")
self.is_windows = sys.platform.startswith('win')

self.absolute_input_html_template_path = os.path.join(self.curr_path, self.input_html_template)
self.absolute_output_folder = os.path.join(self.project_path, self.output_folder)
Expand Down Expand Up @@ -58,11 +61,18 @@ def take_screenshot(self):
if not os.path.exists(self.absolute_output_folder):
os.mkdir(self.absolute_output_folder)

opts = Options()
opts = webdriver.ChromeOptions()
opts.add_argument("--headless")
opts.add_argument("--hide-scrollbars")
opts.add_argument('--force-device-scale-factor=1')
driver = webdriver.Chrome(options=opts)

if not self.is_windows:
binary_location = self.get_chrome()
logger.info(f"Chrome driver found: {binary_location}")
service = Service(executable_path=binary_location)
driver = webdriver.Chrome(service=service, options=opts)
else:
driver = webdriver.Chrome(options=opts)
self.set_viewport_size(driver)

driver.get('file://' + self.output_html_file_path)
Expand All @@ -74,7 +84,7 @@ def take_screenshot(self):
else:
logger.error('ERROR during the screen capture.')

def render(self, timestamp, data_list, destination_folder):
def render(self, timestamp, data_list):
template_loader = FileSystemLoader(self.curr_path)
template = Environment(loader=template_loader, autoescape=True).get_template(self.input_html_template)
rendered_template = template.render(
Expand All @@ -88,16 +98,17 @@ def render(self, timestamp, data_list, destination_folder):
logger.info(f"Template is rendered and saved to {self.output_html_file_path}")
self.take_screenshot()

self.copy_to_destination_folder(destination_folder)

def copy_to_destination_folder(self, destination_folder):
if not destination_folder or not os.path.isdir(destination_folder):
logger.error('Destination folder is not configured properly.')
return

if not os.path.exists(destination_folder):
os.makedirs(destination_folder)
logger.info(f"Destination folder created: {destination_folder}")

shutil.copy(self.output_image_path, destination_folder)
logger.info(f"Image copied to destination folder: {destination_folder}")
# find the chrome driver on Linux distros
def get_chrome(self):
if os.path.isfile('/usr/bin/chromedriver'):
return '/usr/bin/chromedriver'
elif os.path.isfile('/usr/bin/chromium-browser'):
return '/usr/bin/chromium-browser'
elif os.path.isfile('/usr/bin/chromium'):
return '/usr/bin/chromium'
elif os.path.isfile('/usr/bin/chrome'):
return '/usr/bin/chrome'
elif os.path.isfile('/usr/bin/google-chrome'):
return '/usr/bin/google-chrome'
else:
return None