Skip to content

Commit f4c45ca

Browse files
committed
Inkplate10-News(v0.1)
1 parent fa10727 commit f4c45ca

File tree

7 files changed

+156
-1
lines changed

7 files changed

+156
-1
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
InkPlate_News for Soldered Inkplate 10
3+
4+
This project fetches and displays news headlines using a news API.
5+
6+
Setup:
7+
1. Enter your WiFi credentials.
8+
2. Get an API key from https://newsapi.org/ or another news provider.
9+
*/
10+
11+
#include "src/includes.h" // Include necessary libraries and dependencies
12+
13+
// --- WiFi Configuration ---
14+
const char *ssid = "Soldered-testingPurposes";
15+
const char *password = "Testing443";
16+
17+
// --- News API Configuration ---
18+
String apiKey = "10fb57f24c784ee7be7a9cc419b775cc";
19+
String newsEndpoint = "https://newsapi.org/v2/top-headlines?country=us&apiKey=" + apiKey;
20+
21+
// --- Device and Data Objects ---
22+
Inkplate inkplate(INKPLATE_3BIT);
23+
Network network;
24+
Gui gui(inkplate);
25+
26+
// --- Deep Sleep Configuration ---
27+
#define uS_TO_S_FACTOR 1000000
28+
#define TIME_TO_SLEEP 600 // Sleep for 10 minutes
29+
30+
void setup()
31+
{
32+
Serial.begin(115200);
33+
inkplate.begin();
34+
inkplate.clearDisplay();
35+
inkplate.setRotation(1);
36+
37+
// Attempt to connect to WiFi
38+
const unsigned long timeout = 30000;
39+
unsigned long startTime = millis();
40+
bool connected = false;
41+
42+
while (!connected && (millis() - startTime) < timeout)
43+
{
44+
connected = inkplate.connectWiFi(ssid, password, 10, true);
45+
}
46+
47+
// If WiFi failed, display error message
48+
if (!connected)
49+
{
50+
gui.wifiError();
51+
}
52+
else
53+
{
54+
// Fetch and display news
55+
String newsData = network.fetchData(newsEndpoint);
56+
if (newsData.length() > 0)
57+
{
58+
gui.showNews(newsData); // Custom function to display news
59+
}
60+
else
61+
{
62+
gui.showError("Failed to fetch news.");
63+
}
64+
}
65+
66+
// Enter deep sleep
67+
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
68+
esp_deep_sleep_start();
69+
}
70+
71+
void loop()
72+
{
73+
// Empty, main logic is in setup
74+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "Gui.h"
2+
3+
Gui::Gui(Inkplate &display) : display(display) {}
4+
5+
void Gui::wifiError()
6+
{
7+
display.clearDisplay();
8+
display.setTextSize(2);
9+
display.setCursor(10, 10);
10+
display.print("WiFi Connection Failed!");
11+
display.display();
12+
}
13+
14+
void Gui::showError(String message)
15+
{
16+
display.clearDisplay();
17+
display.setTextSize(2);
18+
display.setCursor(10, 10);
19+
display.print(message);
20+
display.display();
21+
}
22+
23+
void Gui::showNews(String newsData)
24+
{
25+
display.clearDisplay();
26+
display.setTextSize(1);
27+
display.setCursor(10, 10);
28+
display.print("News Headlines:");
29+
display.setCursor(10, 30);
30+
display.print(newsData); // Simplified for now
31+
display.display();
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <Inkplate.h>
4+
5+
class Gui
6+
{
7+
public:
8+
Gui(Inkplate &display);
9+
void wifiError();
10+
void showError(String message);
11+
void showNews(String newsData);
12+
13+
private:
14+
Inkplate &display;
15+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "Network.h"
2+
3+
String Network::fetchData(String url)
4+
{
5+
HTTPClient http;
6+
http.begin(url);
7+
int httpCode = http.GET();
8+
9+
if (httpCode > 0)
10+
{
11+
return http.getString();
12+
}
13+
else
14+
{
15+
return "";
16+
}
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include <Arduino.h>
4+
#include <HTTPClient.h>
5+
6+
class Network
7+
{
8+
public:
9+
String fetchData(String url);
10+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#include <Inkplate.h>
4+
#include <WiFi.h>
5+
#include <HTTPClient.h>
6+
#include "Network.h"
7+
#include "Gui.h"

examples/Inkplate6/Projects/Inkplate6_OpenMeteo_Weather_Station/Inkplate6_OpenMeteo_Weather_Station.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
Overview:
99
This example demonstrates how to fetch and display weather data from the OpenMeteo API
10-
using the Inkplate 10 e-paper display.
10+
using the Inkplate 6 e-paper display.
1111
1212
Before You Start:
1313
- Enter your WiFi credentials carefully (they are case-sensitive).

0 commit comments

Comments
 (0)