Raspberry Pi个人生产力跟踪器



我的生产力跟踪器是一个“魔镜”,但是它没有显示时间,天气和动机,而是显示:

  • 我今天在计算机和智能手机上的工作任务上花费了多少时间( RescueTime )。
  • 我的待办事项清单Trello
  • “雷达图”显示了我与昨天(RescueTime)相比在不同类别的应用上花费的时间。
  • 每周总计(RescueTime)。

如果您在工作任务上花费了超过50%的时间,则镜子周围会出现亮绿色的背光。 如果少于50%-背光将变成红色,表示您需要提高生产率! 但是,您可以自己设置分布。





首先,我将解释生产力跟踪器的本质。 然后,我将给出两个不同的工具和组件列表,以便您可以制作不需要焊接能力的完整版或基本版(无LED背光灯)。 接下来,我将向您展示如何为您的项目制作原型,以便您更轻松地制作自己的原型。 您将学习如何使代码适应您的需求,最后,我们将考虑调试设备。

我不会给您现成的菜谱,我只是想展示一种创建跟踪器并询问您问题的方法,以寻找可以带入您的想法,开发项目的答案。

主意




几个月以来,我一直在写这篇文章。 但是我的老朋友拖延症不允许我这样做。 我不停地推迟写作,把自己的时间花在观看YouTube深处的视频上。

一旦我阅读了有关拖延的文章,并找到了可以帮助解决我的问题的服务:Trello任务管理器和RescueTime时间计划程序。 两者都完全符合我的需求,但是一段时间后,我停止浏览他们的页面,开始忽略通知。 然后我想到了我的项目的想法:我想在墙上的镜子上显示来自应用程序的数据。 那我绝对不会掩饰自己的职责。

该项目的初稿很简单:我将使用RescueTime API来显示我的生产/分散注意力的活动,并使用Trello API来显示当天的任务列表。 但是后来我添加了其他功能,但下文对此进行了更多介绍。

工具和组件


我使用这些工具创建了跟踪器,您的设置可能有所不同!

对于框架

  • 4米胶合板7 x 15厘米-取决于显示器的尺寸。
  • 单面镜30 x 40厘米-取决于显示器的尺寸。
  • 显示器25 x 35厘米-在跳蚤市场上找到。 您可以使用任何一个。
  • Raspberry Pi 3 B型-Raspberry Pi 2也适用,但是您必须找到Wi-Fi模块。
  • HDMI电缆

对于LED背光灯

  • Smd5050两米RGB LED灯带-您需要smd5050,我将在下面解释原因。
  • 三个N通道mosfet(例如IRLZ34N)。
  • 电源12 V-2 A.
  • 面包板。

工具

  • 在木头上看见了。
  • 木材胶。
  • 焊接配件(用于LED照明)。

代号




本章由三部分组成,您只需要Raspberry Pi和显示器就可以了,不需要上面列出的所有组件。

配置Raspberry Pi


如果尚未配置Raspberry Pi, 请执行此操作 。 对于项目,您将需要安装Apache Web服务器和PHP-LED控制器。

Apache安装指南: https : //www.raspberrypi.org/documentation/remote-access/web-server/apache.md

PHP-LED控制器安装指南: https : //github.com/k1sul1/Raspberry-Pi-PHP-LED-controller

现在从项目存储库中下载Raspberry Pi上的index.php文件,并将其放在此处: /var/www/html/

如果您不知道如何使用Linux终端传输文件,请阅读: https : //www.linux.com/learn/how-move-files-using-linux-commands-or-file-managers

代码改编


它将需要一点HTML / CSS知识。

我们将改编index.php文件,这是项目的核心。 将显示器连接到Raspberry Pi。 如果尝试打开index.php,则将无法进行任何操作,因为首先需要将API密钥插入代码中。 为此,请在RescueTime网站上登录到您的帐户,转到“开发人员”部分 ,然后单击“激活此密钥”。 将此密钥保存在某处。

对Trello API执行相同的操作:登录到您的帐户并在开发人员门户上生成API密钥

现在,在文本编辑器中的/var/www/html/中打开index.php文件,并将[API_KEY]替换为RescueTime和Trello中的键。 [list_number] -从Trello获取任务列表所需的列表号。 要生成数字,首先在Trello中创建一个新列表并将其命名为“ To-Do”,该列表中的任务将显示在魔术镜上。

现在,从浏览器行中复制地址,如下所示:

https://trello.com/b/3hS6yyLo/board-name

在.json的末尾添加: https : //trello.com/b/3hS6yyLo/board-name.json
按Enter键,屏幕将显示代码。 在此混乱中找到“待办事项”列表的名称,其外观应如下所示: {"name":"To Do","id":"5981c123cd1b23f13907cd18"} ,这里的id是您的列表的标识符。 index.php文件中的[list_number]

现在打开浏览器,在地址栏中输入localhost ,然后按Enter。 图形应显示您的数据。

注意 :图表的位置可能会因显示器的分辨率而异。 您可以在代码的CSS部分中调整元素的宽度,高度和位置。

现在剩下的事情就是为显示器做一个框架并连接LED。

注意 :如果您对API的详细讨论不感兴趣,则可以跳到下一章。

API详细信息


该项目基于两个API:


尽管文档包含所有必要的信息,但我将解释我们的项目使用的API中的哪些数据。

在时间管理部分中,将调用RescueTime API,并要求提供有关今天时间分配的信息:

"https://www.rescuetime.com/anapi/data?key=[API_KEY]&perspective=rank&interval=hour&restrict_begin=".date('Ym-d')."&restrict_end=".date('Ym-d')."&format=json"

在这里
日期('Ym-d') -当前日期。
透视图=等级 -数据排序的类型。 在这种情况下,按“类别”,即花费最多的时间。

进行调用之后,我们将获得JSON格式的文件(请参阅本章结尾处data.json文件的代码)。 从中我们得到“花费的时间(秒)”和“生产率”(它的值可以从-2(分散)到2(生产率))。 根据此数据,可以生成一个值大于100的生产率指数。

以下RescueTime API调用:

"https://www.rescuetime.com/anapi/daily_summary_feed?key=[API_KEY]"

您将收到每周报告(请参阅本章结尾的summary.json文件代码)。 此数据用于建立每周计划。

调用Trello API:

"https://api.trello.com/1/lists/[list_number]/cards?fields=name&key=[API_KEY]&token=[Token]"

您将从Trello中的任务卡接收数据:

[{"id":"5a4160103bfcd14994852f59","name":"ceylan cinemagraph"},{"id":"59e8241f6aa8662a51eb7de6","name":"Learn GitHuB"},{"id":"5981c19577c732f826ad8025","name":"Publish Instructible"},{"id":"5a341dba7f17d235d7c5bbd1","name":"SPACE PROGRAM"}]

您可以在卡中放置文本,然后将其传输到其他地方。

data.json

代号
 Formatted JSON Data { "notes":"data is an array of arrays (rows), column names for rows in row_headers", "row_headers":[ "Rank", "Time Spent (seconds)", "Number of People", "Activity", "Category", "Productivity" ], "rows":[ [ 1, 1536, 1, "en.0wikipedia.org", "Uncategorized", 0 ], [ 2, 1505, 1, "youtube.com", "Video", -2 ], [ 3, 1178, 1, "OpenOffice", "Writing", 2 ], [ 4, 709, 1, "moodle.bilkent.edu.tr", "General Reference \u0026 Learning", 2 ], [ 5, 602, 1, "google.com.tr", "Search", 2 ], [ 6, 439, 1, "reddit.com", "General News \u0026 Opinion", -2 ], [ 7, 437, 1, "tr.sharelatex.com", "Writing", 2 ], [ 8, 361, 1, "yemeksepeti.com", "General Shopping", -2 ], [ 9, 356, 1, "Gmail", "Email", 0 ], [ 10, 328, 1, "Google Chrome", "Browsers", 0 ], [ 11, 207, 1, "stars.bilkent.edu.tr", "General Reference \u0026 Learning", 2 ], [ 12, 179, 1, "whatsapp", "Instant Message", -1 ], 

summary.json

代号
 [ { "id":1515657600, "date":"2018-01-11", "productivity_pulse":54, "very_productive_percentage":34.2, "productive_percentage":10.6, "neutral_percentage":25.6, "distracting_percentage":0.0, "very_distracting_percentage":29.6, "all_productive_percentage":44.8, "all_distracting_percentage":29.6, "uncategorized_percentage":16.1, "business_percentage":6.0, "communication_and_scheduling_percentage":4.3, "social_networking_percentage":0.0, "design_and_composition_percentage":0.0, "entertainment_percentage":15.2, "news_percentage":3.3, "software_development_percentage":5.4, "reference_and_learning_percentage":22.8, "shopping_percentage":12.9, "utilities_percentage":14.1, "total_hours":2.51, "very_productive_hours":0.86, "productive_hours":0.27, "neutral_hours":0.64, "distracting_hours":0.0, "very_distracting_hours":0.74, "all_productive_hours":1.12, "all_distracting_hours":0.74, "uncategorized_hours":0.4, "business_hours":0.15, "communication_and_scheduling_hours":0.11, "social_networking_hours":0.0, "design_and_composition_hours":0.0, "entertainment_hours":0.38, "news_hours":0.08, "software_development_hours":0.13, "reference_and_learning_hours":0.57, "shopping_hours":0.32, "utilities_hours":0.35, "total_duration_formatted":"2h 30m", "very_productive_duration_formatted":"51m 26s", "productive_duration_formatted":"15m 56s", "neutral_duration_formatted":"38m 34s", "distracting_duration_formatted":"no time", "very_distracting_duration_formatted":"44m 30s", "all_productive_duration_formatted":"1h 7m", "all_distracting_duration_formatted":"44m 30s", "uncategorized_duration_formatted":"24m 11s", "business_duration_formatted":"9m 6s", "communication_and_scheduling_duration_formatted":"6m 26s", "social_networking_duration_formatted":"no time", "design_and_composition_duration_formatted":"no time", "entertainment_duration_formatted":"22m 49s", "news_duration_formatted":"4m 55s", "software_development_duration_formatted":"8m 3s", "reference_and_learning_duration_formatted":"34m 17s", "shopping_duration_formatted":"19m 22s", "utilities_duration_formatted":"21m 17s" }, { "id":1515571200, "date":"2018-01-10", "productivity_pulse":33, "very_productive_percentage":21.9, "productive_percentage":2.3, "neutral_percentage":14.4, "distracting_percentage":11.0, "very_distracting_percentage":50.3, "all_productive_percentage":24.2, "all_distracting_percentage":61.4, "uncategorized_percentage":0.3, "business_percentage":0.0, "communication_and_scheduling_percentage":13.5, "social_networking_percentage":0.0, "design_and_composition_percentage":6.3, "entertainment_percentage":44.7, "news_percentage":4.2, "software_development_percentage":0.0, "reference_and_learning_percentage":15.5, "shopping_percentage":0.0, "utilities_percentage":15.4, "total_hours":2.24, "very_productive_hours":0.49, "productive_hours":0.05, "neutral_hours":0.32, "distracting_hours":0.25, "very_distracting_hours":1.13, "all_productive_hours":0.54, "all_distracting_hours":1.37, "uncategorized_hours":0.01, "business_hours":0.0, "communication_and_scheduling_hours":0.3, "social_networking_hours":0.0, "design_and_composition_hours":0.14, "entertainment_hours":1.0, "news_hours":0.09, "software_development_hours":0.0, "reference_and_learning_hours":0.35, "shopping_hours":0.0, "utilities_hours":0.34, "total_duration_formatted":"2h 14m", "very_productive_duration_formatted":"29m 22s", "productive_duration_formatted":"3m 8s", "neutral_duration_formatted":"19m 18s", "distracting_duration_formatted":"14m 48s", "very_distracting_duration_formatted":"1h 7m", "all_productive_duration_formatted":"32m 30s", "all_distracting_duration_formatted":"1h 22m", "uncategorized_duration_formatted":"27s", "business_duration_formatted":"1s", "communication_and_scheduling_duration_formatted":"18m 5s", "social_networking_duration_formatted":"no time", "design_and_composition_duration_formatted":"8m 30s", "entertainment_duration_formatted":"59m 54s", "news_duration_formatted":"5m 39s", "software_development_duration_formatted":"no time", "reference_and_learning_duration_formatted":"20m 51s", "shopping_duration_formatted":"no time", "utilities_duration_formatted":"20m 39s" }, { "id":1515484800, "date":"2018-01-09", "productivity_pulse":68, "very_productive_percentage":60.4, "productive_percentage":0.5, "neutral_percentage":11.0, "distracting_percentage":7.1, "very_distracting_percentage":21.0, "all_productive_percentage":60.9, "all_distracting_percentage":28.1, "uncategorized_percentage":9.1, "business_percentage":21.9, "communication_and_scheduling_percentage":7.2, "social_networking_percentage":5.1, "design_and_composition_percentage":1.2, "entertainment_percentage":1.6, "news_percentage":12.5, "software_development_percentage":9.1, "reference_and_learning_percentage":28.2, "shopping_percentage":2.9, "utilities_percentage":1.2, "total_hours":2.78, "very_productive_hours":1.68, "productive_hours":0.01, "neutral_hours":0.31, "distracting_hours":0.2, "very_distracting_hours":0.58, "all_productive_hours":1.69, "all_distracting_hours":0.78, "uncategorized_hours":0.25, "business_hours":0.61, "communication_and_scheduling_hours":0.2, "social_networking_hours":0.14, "design_and_composition_hours":0.03, "entertainment_hours":0.04, "news_hours":0.35, "software_development_hours":0.25, "reference_and_learning_hours":0.78, "shopping_hours":0.08, "utilities_hours":0.03, "total_duration_formatted":"2h 46m", "very_productive_duration_formatted":"1h 40m", "productive_duration_formatted":"47s", "neutral_duration_formatted":"18m 23s", "distracting_duration_formatted":"11m 49s", "very_distracting_duration_formatted":"34m 57s", "all_productive_duration_formatted":"1h 41m", "all_distracting_duration_formatted":"46m 46s", "uncategorized_duration_formatted":"15m 7s", "business_duration_formatted":"36m 26s", "communication_and_scheduling_duration_formatted":"11m 59s", "social_networking_duration_formatted":"8m 28s", "design_and_composition_duration_formatted":"2m 4s", "entertainment_duration_formatted":"2m 39s", "news_duration_formatted":"20m 49s", "software_development_duration_formatted":"15m 5s", "reference_and_learning_duration_formatted":"46m 59s", "shopping_duration_formatted":"4m 51s", "utilities_duration_formatted":"2m 3s" } ] 

原型制作


图片





数据现在显示在监视器上,是时候设计框架和镜子了。 这完全取决于您的喜好。 我拿了轻木,因为它更适合我的内饰。

如果要选择其他框架设计,则有一些出色的指南:

https://www.instructables.com/id/Smart-Mirror-by-Raspberry-Pi/
https://www.instructables.com/id/Raspberry-Pi-Smart-Mirror/
https://www.instructables.com/id/Magic-Mirror/

我的相框的空白尺寸:

正面:

  • 2 x 40厘米
  • 2 x 47厘米

背面:

  • 2 x 38厘米
  • 2 x 50厘米

镜框组装


图片





一些注意事项:

  • 为了建造框架,我用了木胶。 将镜子安装到框架中后,我还在角落粘贴了木制三角形以固定镜子。 但是后来我意识到这不是最佳解决方案,因为由于三角形,框架不会压在墙上。
  • 在粘上零件之前,请将所有东西弄干,检查显示器周围是否有缝隙或其他缺陷。

电子组装


















如果要制作不带LED的基本版本,则可以跳过相应的步骤。

LED的组装和安装图来自两个不同的手册

如何使用Raspberry Pi控制RGB LED带
Raspberry Pi PHP LED控制器

重要说明

我使用了这些针脚:

  • GPIO17为红线。
  • GPIO22用于绿线。
  • GPIO24为蓝线。

如果要使用其他引脚,则必须在index.php的开头更改其编号。

检查一下




一切正常,但是您需要使用鼠标和键盘来启动浏览器并输入localhost。

1.启动终端,然后输入: sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart
2.然后输入: chromium-browser --kiosk --incognito "http://localhost/index.php"

现在,您可以关闭鼠标和键盘。 浏览器应启动并打开index.php文件。

故障排除


我有一个API错误
我们的API对点击数有限制。 如果拉得太频繁,则会出错。 要解决此问题,请向index.php添加更新延迟,默认值为360秒。

#Seconds to refresh the webpage<br>$sec = "360";

浏览器在启动时无法打开
在不同的操作系统中,自动启动文件位于不同的位置。 我使用了Raspbian GNU / Linux 8.0 Jessie,因此请检查此文件在您的OS上的位置。

LED以不同颜色发光
LED灯条的连接可能会有所不同,并且请确保颜色连接混合在一起。 您可以通过将电线焊接到正确的触点来解决此问题。 您也可以使用index.php中的十六进制值微调突出显示的颜色。

if ($oran<50) { $led->setHex("#FF0000"); }else { $led->setHex("#00FF00"); }

这是一个十六进制颜色计算器 ,可以为您提供帮助。

我想使用其他图形
我应用了chart.js JS库。 如果要使用其他图表,请阅读文档: http : //www.chartjs.org/samples/latest/

接下来是什么


有很多方法可以改善这个项目。 例如:

  • 屏幕更大 :然后您可以显示更多的图形,或者将部分区域保留在镜子下面。
  • 集成不同的API :如今,可以使用大量的各种API(Twitter,Google和许多其他API)。 我想到了使用Spotify API的想法,以在镜子上显示当前正在播放的歌曲。 这是集思广益会议的列表: www.programmableweb.com/apis/directory
  • 语音控制Amazon Alexa :我有这样的设备,我可以借助语音控制灯光。 您可以拧Alex来控制镜子上的图形。

Source: https://habr.com/ru/post/zh-CN411797/


All Articles