Проблема с ngrok и arduino ide с esp8266 - PullRequest
0 голосов
/ 06 февраля 2019

Когда я пытаюсь подключить свой esp8266 к ngork с помощью arduino ide, ngrok говорит: ошибка 502 плохой шлюз, он открывает localhost: 4040 и я использую порт 8080, это проблема?Если я использую порт 4040, у меня есть другая проблема: 404 Не найден на ngrok

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

/* wifi network name */
char* ssidName = "2G_TNCAPA81F7F_EXT";
/* WPA2 PSK password */
char* pwd = "EB86E9FFFF";
/* service IP address */ 
char* address = "http://aa71fb53.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);  

}

Я не могу найти решение, на данный момент ngrok отвечает следующим образом:

<!doctype html5>
<html>
    <head>
        <style type="text/css">

        strong { font-weight: bold; }
        hr { -moz-box-sizing: content-box; box-sizing: content-box; height: 0; }
        html { font-family: sans-serif;   -ms-text-size-adjust: 100%;   -webkit-text-size-adjust: 100%;   } body { margin: 0; }
        a { background-color: transparent; }
        a:active, a:hover { outline: 0; }
        </style>

        <style type="text/css">
            body { background-color: #f5f5f5; }
            .container { width: 500px; margin: auto; color: #444; padding: 5px; }
            a, strong { color: purple; text-decoration: none; }
            a:hover { text-decoration: underline; }
            h2 { text-align: center; color: #000; }
            p { line-height: 20px; }
        </style>
    </head>
    <body>
        <div class="container">


<h2>Failed to complete tunnel connection</h2>
<hr />
<p>
    The connection to <strong><a href="http://aa71fb53.ngrok.io">http://aa71fb53.ngrok.io</a></strong>
    was successfully tunneled to your ngrok client,
    but the client failed to establish a connection to
    the local address <strong><a href="http://localhost:8080">localhost:8080</a></strong>.
</p>
<p>
    Make sure that a web service is running on
    <strong><a href="http://localhost:8080">localhost:8080</a></strong> and that it is a valid address.
</p>
<p>
    The error encountered was: <strong style="color: #9E2929">dial tcp [::1]:8080: connectex: Impossibile stabilire la connessione. Rifiuto persistente del computer di destinazione.</strong>
</p>


        </div>
    </body>
</html>
...