Redact embedded voice assistant credentials
This commit is contained in:
@@ -1,148 +1,148 @@
|
|||||||
// Include necessary libraries
|
// Include necessary libraries
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_ILI9341.h>
|
#include <Adafruit_ILI9341.h>
|
||||||
|
|
||||||
// WiFi credentials
|
// WiFi credentials
|
||||||
const char* ssid = "thetempleofdoom";
|
const char* ssid = "REPLACE_WITH_WIFI_SSID";
|
||||||
const char* password = "myhandsonmyself";
|
const char* password = "REPLACE_WITH_WIFI_PASSWORD";
|
||||||
|
|
||||||
// Gemini API key
|
// Gemini API key
|
||||||
const char* geminiApiKey = "AIzaSyAzFzg_MAcwoH3O-nfriBjlFw5x6UBU5hk";
|
const char* geminiApiKey = "REPLACE_WITH_GOOGLE_API_KEY";
|
||||||
|
|
||||||
// Pin for the button
|
// Pin for the button
|
||||||
// IMPORTANT: Please verify the pin number for your button and update the value below.
|
// IMPORTANT: Please verify the pin number for your button and update the value below.
|
||||||
const int buttonPin = 0;
|
const int buttonPin = 0;
|
||||||
|
|
||||||
// Display pins
|
// Display pins
|
||||||
// IMPORTANT: Please verify the pin numbers for your display and update the values below.
|
// IMPORTANT: Please verify the pin numbers for your display and update the values below.
|
||||||
#define TFT_CS 5
|
#define TFT_CS 5
|
||||||
#define TFT_DC 4
|
#define TFT_DC 4
|
||||||
#define TFT_RST -1 // Reset pin (often not needed)
|
#define TFT_RST -1 // Reset pin (often not needed)
|
||||||
|
|
||||||
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
|
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// Initialize serial communication
|
// Initialize serial communication
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
// Initialize the button pin
|
// Initialize the button pin
|
||||||
pinMode(buttonPin, INPUT_PULLUP);
|
pinMode(buttonPin, INPUT_PULLUP);
|
||||||
|
|
||||||
// Connect to WiFi
|
// Connect to WiFi
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
Serial.println("Connecting to WiFi...");
|
Serial.println("Connecting to WiFi...");
|
||||||
}
|
}
|
||||||
Serial.println("Connected to WiFi");
|
Serial.println("Connected to WiFi");
|
||||||
Serial.print("IP Address: ");
|
Serial.print("IP Address: ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
// Initialize the display
|
// Initialize the display
|
||||||
tft.begin();
|
tft.begin();
|
||||||
tft.setRotation(3);
|
tft.setRotation(3);
|
||||||
tft.fillScreen(ILI9341_BLACK);
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
tft.setTextColor(ILI9341_GREEN);
|
tft.setTextColor(ILI9341_GREEN);
|
||||||
tft.setTextSize(2);
|
tft.setTextSize(2);
|
||||||
tft.println("Hacker Voice Assistant");
|
tft.println("Hacker Voice Assistant");
|
||||||
tft.println("--------------------");
|
tft.println("--------------------");
|
||||||
tft.setTextSize(1);
|
tft.setTextSize(1);
|
||||||
tft.print("IP: ");
|
tft.print("IP: ");
|
||||||
tft.println(WiFi.localIP());
|
tft.println(WiFi.localIP());
|
||||||
tft.setTextSize(2);
|
tft.setTextSize(2);
|
||||||
tft.println("\nReady for command...");
|
tft.println("\nReady for command...");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// Check if the button is pressed
|
// Check if the button is pressed
|
||||||
if (digitalRead(buttonPin) == LOW) {
|
if (digitalRead(buttonPin) == LOW) {
|
||||||
// Start a voice session
|
// Start a voice session
|
||||||
startVoiceSession();
|
startVoiceSession();
|
||||||
// After the session, clear the screen and show the ready message again
|
// After the session, clear the screen and show the ready message again
|
||||||
tft.fillScreen(ILI9341_BLACK);
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
tft.setCursor(0,0);
|
tft.setCursor(0,0);
|
||||||
tft.setTextSize(2);
|
tft.setTextSize(2);
|
||||||
tft.println("Hacker Voice Assistant");
|
tft.println("Hacker Voice Assistant");
|
||||||
tft.println("--------------------");
|
tft.println("--------------------");
|
||||||
tft.setTextSize(1);
|
tft.setTextSize(1);
|
||||||
tft.print("IP: ");
|
tft.print("IP: ");
|
||||||
tft.println(WiFi.localIP());
|
tft.println(WiFi.localIP());
|
||||||
tft.setTextSize(2);
|
tft.setTextSize(2);
|
||||||
tft.println("\nReady for command...");
|
tft.println("\nReady for command...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void startVoiceSession() {
|
void startVoiceSession() {
|
||||||
// Clear the screen for the new session
|
// Clear the screen for the new session
|
||||||
tft.fillScreen(ILI9341_BLACK);
|
tft.fillScreen(ILI9341_BLACK);
|
||||||
tft.setCursor(0,0);
|
tft.setCursor(0,0);
|
||||||
tft.setTextSize(2);
|
tft.setTextSize(2);
|
||||||
|
|
||||||
// TODO: Add voice recording and processing code here
|
// TODO: Add voice recording and processing code here
|
||||||
Serial.println("Button pressed, starting voice session...");
|
Serial.println("Button pressed, starting voice session...");
|
||||||
displayHackerText("Listening...");
|
displayHackerText("Listening...");
|
||||||
|
|
||||||
// For now, we'll just send a test query to Gemini
|
// For now, we'll just send a test query to Gemini
|
||||||
delay(2000); // Simulate recording time
|
delay(2000); // Simulate recording time
|
||||||
displayHackerText("Processing...");
|
displayHackerText("Processing...");
|
||||||
String query = "Hello, Gemini!";
|
String query = "Hello, Gemini!";
|
||||||
String response = sendToGemini(query);
|
String response = sendToGemini(query);
|
||||||
|
|
||||||
// Display the response
|
// Display the response
|
||||||
displayHackerText("User: " + query);
|
displayHackerText("User: " + query);
|
||||||
displayHackerText("Gemini: " + response);
|
displayHackerText("Gemini: " + response);
|
||||||
Serial.println("Gemini response: " + response);
|
Serial.println("Gemini response: " + response);
|
||||||
}
|
}
|
||||||
|
|
||||||
String sendToGemini(String query) {
|
String sendToGemini(String query) {
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
String url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=";
|
String url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=";
|
||||||
url += geminiApiKey;
|
url += geminiApiKey;
|
||||||
|
|
||||||
http.begin(url);
|
http.begin(url);
|
||||||
http.addHeader("Content-Type", "application/json");
|
http.addHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
StaticJsonDocument<200> doc;
|
StaticJsonDocument<200> doc;
|
||||||
JsonObject content = doc.createNestedObject("contents");
|
JsonObject content = doc.createNestedObject("contents");
|
||||||
JsonArray parts = content.createNestedArray("parts");
|
JsonArray parts = content.createNestedArray("parts");
|
||||||
JsonObject part = parts.createNestedObject();
|
JsonObject part = parts.createNestedObject();
|
||||||
part["text"] = query;
|
part["text"] = query;
|
||||||
|
|
||||||
String requestBody;
|
String requestBody;
|
||||||
serializeJson(doc, requestBody);
|
serializeJson(doc, requestBody);
|
||||||
|
|
||||||
int httpResponseCode = http.POST(requestBody);
|
int httpResponseCode = http.POST(requestBody);
|
||||||
|
|
||||||
if (httpResponseCode > 0) {
|
if (httpResponseCode > 0) {
|
||||||
String payload = http.getString();
|
String payload = http.getString();
|
||||||
StaticJsonDocument<1024> responseDoc;
|
StaticJsonDocument<1024> responseDoc;
|
||||||
DeserializationError error = deserializeJson(responseDoc, payload);
|
DeserializationError error = deserializeJson(responseDoc, payload);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
Serial.print(F("deserializeJson() failed: "));
|
Serial.print(F("deserializeJson() failed: "));
|
||||||
Serial.println(error.f_str());
|
Serial.println(error.f_str());
|
||||||
return "Error: Failed to parse response.";
|
return "Error: Failed to parse response.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (responseDoc.containsKey("candidates")) {
|
if (responseDoc.containsKey("candidates")) {
|
||||||
const char* responseText = responseDoc["candidates"][0]["content"]["parts"][0]["text"];
|
const char* responseText = responseDoc["candidates"][0]["content"]["parts"][0]["text"];
|
||||||
return String(responseText);
|
return String(responseText);
|
||||||
} else {
|
} else {
|
||||||
return "Error: Invalid response from Gemini.";
|
return "Error: Invalid response from Gemini.";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Serial.print("Error on sending POST: ");
|
Serial.print("Error on sending POST: ");
|
||||||
Serial.println(httpResponseCode);
|
Serial.println(httpResponseCode);
|
||||||
return "Error: Unable to get response from Gemini.";
|
return "Error: Unable to get response from Gemini.";
|
||||||
}
|
}
|
||||||
|
|
||||||
http.end();
|
http.end();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayHackerText(String text) {
|
void displayHackerText(String text) {
|
||||||
tft.println(text);
|
tft.println(text);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user