-
Notifications
You must be signed in to change notification settings - Fork 7.7k
-
图片
My test server does not have any of the verification, but how can I adjust this issue? My code is down below. This is my first time in dealing with HTTP/2.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments
-
#include <WiFi.h>
#include <ArduinoJson.h>
//#include "sh2lib.h"
extern "C" {
#include "sh2lib.h"
}
#define SWITCH_PIN 4
const char* ssid = "aaa";
const char* password = "sss";
const char* URL = "http://192.168.1.12:8080";
const char* UPLOAD = "/upload";
const char* ntpServer = "pool.ntp.org";
const char *timezoneEST = "EST5EDT,M3.2.0/2,M11.1.0";
const long gmtOffset_sec = 3600;
const int daylightOffset_sec = 3600;
int layer = 1;
int job_id = 1; //1000 layers will be trigger to end
unsigned long job_order = 1; //10 jobs to update one layer
StaticJsonDocument<128> doc; // for JSON data
char toSend[128];
struct sh2lib_handle hd;
int handle_post_response(struct sh2lib_handle *handle, const char *data, size_t len, int flags)
{
if (len > 0) {
Serial.printf("%.*s\n", len, data);
}
if (flags == DATA_RECV_RST_STREAM) {
Serial.println("STREAM CLOSED");
}
return 0;
}
int send_json_data(struct sh2lib_handle *handle, char *buf, size_t length, uint32_t *data_flags)
{
int copylen = strlen(toSend);
if (copylen < length) {
memcpy(buf, toSend, copylen); //TODO: replace this directly points to toSend to see whether it works or not
} else {
copylen = 0;
}
*data_flags |= NGHTTP2_DATA_FLAG_EOF;
return copylen;
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(SWITCH_PIN, INPUT);
// pinMode(SWITCH_PIN2, INPUT);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Failed!");
return;
}
Serial.println();
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
Serial.println(WiFi.softAPIP());
if (sh2lib_connect(&hd, URL) != ESP_OK) {
Serial.println("Error connecting to HTTP2 server");
return;
}
doc["Machine_ID"] = 5;
}
void loop() {
// put your main code here, to run repeatedly:
float x_pos = (float)random(0,25);
float y_pos = (float)random(0,25);
float x_act = x_pos * random(0,2);
float y_act = y_pos * random(0,2);
if(digitalRead(SWITCH_PIN) == HIGH && job_order <= 4294967295){
doc["Job_ID"] = job_id;
doc["Job_order"] = job_order;
doc["Layer"] = layer;
doc["X_pos"] = x_pos;
doc["Y_pos"] = y_pos;
doc["X_act"] = x_act;
doc["Y_act"] = y_act;
serializeJson(doc, Serial);
Serial.println();
serializeJson(doc, toSend);
sh2lib_do_post(&hd, UPLOAD, send_json_data, handle_post_response);
if(job_order % 10 == 0){
layer++;
//job_order = 1;
}
job_order++;
if(layer == 1000){
//job_order = 1;
job_id++;
layer = 1;
}
//delay(1); //ms
}
}
Beta Was this translation helpful? Give feedback.
All reactions
-
The current support for HTTP/2 is through the ESP-IDF and not from Arduino API. You can use the ESP-IDF APIs inside your Arduino code.
Here is a starting point: #1130 (comment)
The Arduino API for HTTP/2 will be implemented in a future release of the Arduino-ESP32 Core.
Beta Was this translation helpful? Give feedback.