Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Why i should use Protocol #11839

Closed Unanswered
RagingApple asked this question in Q&A
Discussion options

Board

esp32 c5 dev module

Device Description

#include <Arduino.h>
#include <string.h>
#include <WiFiMulti.h>
#include <ArduinoJson.h>
#include <HTTPClient.h>
#include <WiFi.h>

const char* ssid = "Consered";
const char* password = "Consered";
const char* deepseek_API = "Mostly Consered Hmm";
String res = "";

void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.disconnect();

while (!Serial);

// Connect to WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}

Serial.println("\nConnected to WiFi");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}

void loop() {
Serial.print("Ask your Question : ");
while (!Serial.available());

while (Serial.available()) {
char add = Serial.read();
res += add;
delay(1);
}

int len = res.length();
res = res.substring(0, len - 2);
res = """ + res + """;
Serial.println(res);

HTTPClient https;

if (https.begin("https://openrouter.ai/api/v1")) { // HTTPS
https.addHeader("Content-Type", "application/json");
String token_key = String("Bearer ") + deepseek_API;
https.addHeader("Authorization", token_key);

String payload = String("{\"model\":\"deepseek/deepseek-chat-v3.1:free\",\"messages\":[{\"role\":\"user\",\"content\":") + res + String("}]}");
Serial.print("Sending Payload: ");
Serial.println(payload);
int httpCode = https.POST(payload);
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
 Serial.println("Response received. Reading payload...");
 // Read the response dynamically until the entire payload is received
 String response = "";
 WiFiClient* stream = https.getStreamPtr();
 unsigned long lastReadTime = millis();
 const unsigned long timeoutPeriod = 15000; // 15s timeout
 while (true) {
 while (stream->available()) {
 char c = stream->read();
 response += c;
 lastReadTime = millis(); // reset timeout
 }
 if (millis() - lastReadTime > timeoutPeriod) {
 break; // exit if no new data for timeoutPeriod
 }
 }
 response = response.substring(4);
 Serial.println("Complete Payload:");
 Serial.println(response);
 JsonDocument doc;
 DeserializationError error = deserializeJson(doc, response);
 if (error) {
 Serial.print("deserializeJson() failed: ");
 Serial.println(error.c_str());
 return;
 }
 String Answer = doc["choices"][0]["message"]["content"];
 // Answer = Answer.substring(2);
 Serial.print("Answer = ");
 Serial.println(Answer);
} else {
 Serial.printf("[HTTPS] POST failed, error: %s\n", https.errorToString(httpCode).c_str());
}
https.end();

} else {
Serial.println("[HTTPS] Unable to connect");
}

Serial.println("Wait 10s before next round...");
res = "";
delay(10000);
}
I wrote this code before but my favorite arduino ide saying to me:

Image

Hardware Configuration

Oh

Version

v3.1.2

Type

Question

IDE Name

Oh

Operating System

Window11

Flash frequency

I don't think you have to know

PSRAM enabled

no

Upload speed

921600

Description

wifi:can not get wifi protocol under WiFi band mode WIFI_BAND_MODE_AUTO, please use esp_wifi_get_protocols instead
I should solve it. And why this words is blocking me?

Sketch

?

Debug Message

?

Other Steps to Reproduce

?

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Status: Awaiting triage Issue is waiting for triage
1 participant
Converted from issue

This discussion was converted from issue #11837 on September 15, 2025 15:12.

AltStyle によって変換されたページ (->オリジナル) /