You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For this example you will need only USB cable and Inkplate 10.
6
+
Select "e-radionica Inkplate10" or "Soldered Inkplate10" from Tools -> Board menu.
7
+
Don't have "e-radionica Inkplate10" or "Soldered Inkplate10" option? Follow our tutorial and add it:https://soldered.com/documentation/inkplate/6/quick-start-guide/
8
+
9
+
Overview:
10
+
This example demonstrates how to fetch the temperature and weather, then with that information it creates a snarky prompt which is displayed
11
+
on the Inkplate
12
+
13
+
Before You Start:
14
+
- Enter your WiFi credentials carefully (they are case-sensitive).
15
+
- Update the following variables for accurate local weather data:
16
+
• location
17
+
• latitude
18
+
• longitude
19
+
- After creating an OpenAI API key, enter it in the openai_key variable
20
+
*/
21
+
22
+
23
+
#include<WiFiClientSecure.h>// Secure WiFi client for HTTPS communication
24
+
#include<ArduinoJson.h>// Library for parsing and generating JSON
25
+
#include"Inkplate.h"// Inkplate display driver
26
+
#include"FreeMonoBold18pt7b.h"// Font used for rendering text on the display
27
+
28
+
// How long the device will stay in deep sleep (in minutes)
29
+
#defineSLEEP_DURATION_IN_MINS30*60
30
+
31
+
// WiFi credentials
32
+
constchar* ssid = "YOUR_SSID";
33
+
constchar* password = "YOUR_PASSWORD";
34
+
35
+
// OpenAI API key
36
+
constchar* openai_key = "YOUR_API_KEY_HERE";
37
+
38
+
// Location and coordinates for weather query
39
+
String location = "Osijek";
40
+
constfloat latitude = 45.5600;
41
+
constfloat longitude = 18.6750;
42
+
43
+
// Variables to hold weather data
44
+
float temperature;
45
+
String weatherDesc, timeStr;
46
+
47
+
// HTTPS client instance
48
+
WiFiClientSecure client;
49
+
50
+
// Inkplate display instance (1-bit mode for faster update and lower power usage)
51
+
Inkplate display(INKPLATE_1BIT);
52
+
53
+
voidsetup() {
54
+
display.begin(); // Initialize the Inkplate display
55
+
56
+
Serial.begin(115200); // Initialize serial for debugging
57
+
58
+
// Connect to WiFi
59
+
display.print("Connecting to WiFi...");
60
+
WiFi.begin(ssid, password);
61
+
while (WiFi.status() != WL_CONNECTED) {
62
+
delay(500);
63
+
display.print(".");
64
+
display.partialUpdate(); // Refresh only changed parts of display for faster performance
65
+
}
66
+
67
+
display.println("\nConnected!");
68
+
display.display(); // Show connection message
69
+
display.clearDisplay(); // Clear display for next content
70
+
71
+
// Get current weather data
72
+
if (getWeather(latitude, longitude, temperature, weatherDesc, timeStr)) {
73
+
// Build prompt to send to OpenAI
74
+
String prompt = "Give me a sarcastic 120-word max summary of the weather in " + location +
75
+
". It's currently " + String(temperature, 1) + "C with " + weatherDesc +
76
+
" skies at " + timeStr +
77
+
" (Just take the Hour and minutes, without AM or PM). Make it witty and slightly condescending. Dont use '—' and ' symbols, use - and ' respectively";
0 commit comments