问题
I have a problem with ngrok and arduino, i send a message but when i open ngrok it says: 404 Not found
I think it could be problem with port, I use 4040 because ngrok open localhost:4040 but i don't know if it is true. The server-side app on java use port 80
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
/* wifi network name */
char* ssidName = "mywifi";
/* WPA2 PSK password */
char* pwd = "mypwd";
/* service IP address */
char* address = "http://cf3c013e.ngrok.io";
void setup() {
Serial.begin(115200);
WiFi.begin(ssidName, pwd);
Serial.print("Connecting...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected: \n local IP: "+WiFi.localIP());
}
int sendData(String address, float value, String place){
HTTPClient http;
http.begin(address + "/api/data");
http.addHeader("Content-Type", "application/json");
String msg =
String("{ \"value\": ") + String(value) +
", \"place\": \"" + place +"\" }";
int retCode = http.POST(msg);
http.end();
String payload = http.getString();
Serial.println(payload);
return retCode;
}
void loop() {
if (WiFi.status()== WL_CONNECTED){
/* read sensor */
float value = (float) analogRead(A0) / 1023.0;
/* send data */
Serial.print("sending "+String(value)+"...");
int code = sendData(address, value, "home");
/* log result */
if (code == 200){
Serial.println("ok");
} else {
Serial.println("error");
}
} else {
Serial.println("Error in WiFi connection");
}
delay(5000);
}
回答1:
Remove http://
from char* address = "http://cf3c013e.ngrok.io";
The double-up of http declaration in the address is likely causing the 404.
来源:https://stackoverflow.com/questions/54543748/404-not-found-on-ngrok