• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
MKT-porter
博客园    首页    新随笔    联系   管理    订阅  订阅
Arduino内部网页代理,网页穿透,公网访问Arduino内部网页
#include <ESP8266WiFi.h>
const char* id     = "id";  //http://www.mcunode.com/proxy/id/LED  if id==4567  then url:http://www.mcunode.com/proxy/4567/LED
const char* ssid     = "ssid";
const char* password = "password";
int ledPin = 13;
const char* host = "www.mcunode.com";

void setup() {
  Serial.begin(115200);
  delay(10);

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

int value = 0;

void loop() {
  delay(5000);
  ++value;

  Serial.print("connecting to ");
  Serial.println(host);
  
  WiFiClient client;
  const int httpPort = 8001;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }


 if (client.connected())
{
  client.write(id);
  delay(1000);
  while (1)
  {

  String request = client.readStringUntil('\r');
  Serial.print(request);
  client.flush();
 
  int value = LOW;
  if (request.indexOf("/LED=ON") != -1)  {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED=OFF") != -1)  {
    digitalWrite(ledPin, LOW);
    value = LOW;
  }
 Serial.println(value);


  if(value == HIGH) {
    client.print("<h1> ESP8266 Arduino Web Server</h1>Led pin is now:on <br><br><a href="LED=ON""><button>Turn On </button></a><a href="LED=OFF""><button>Turn Off </button></a><br />");
  } else {
    client.print("<h1> ESP8266 Arduino Web Server</h1>Led pin is now:off  <br><br><a href="LED=ON""><button>Turn On </button></a><a href="LED=OFF""><button>Turn Off </button></a><br />");
  }
  
  }
}
}

  

Arduino内部网页代理,网页穿透,公网访问Arduino内部网页
项目地址:https://github.com/IoTServ/esp8266-Arduino-web-proxy/tree/master
看下效果: <ignore_js_op><ignore_js_op> 

好了上代码:
posted on 2019-03-29 05:12  MKT-porter  阅读(762)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3