Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Server 如何使用2节点MCU作为我的家庭wifi网络上的服务器和客户端,因为该网络覆盖我的家庭的各个角落,用于物联网设备_Server_Arduino_Client_Esp8266_Nodemcu - Fatal编程技术网

Server 如何使用2节点MCU作为我的家庭wifi网络上的服务器和客户端,因为该网络覆盖我的家庭的各个角落,用于物联网设备

Server 如何使用2节点MCU作为我的家庭wifi网络上的服务器和客户端,因为该网络覆盖我的家庭的各个角落,用于物联网设备,server,arduino,client,esp8266,nodemcu,Server,Arduino,Client,Esp8266,Nodemcu,如何使用2节点MCU作为我的家庭wifi网络的服务器和客户端,因为该网络覆盖了我家的各个角落,可用于IOT设备 我的服务器端代码工作得很好,唯一的问题是按照我的假设,客户端代码。 将服务器和客户端与其中一个节点mcu的热点连接的过程在互联网上随处可见,但如何将两个节点mcu模块与家庭wifi连接,并仍用作服务器和客户端,未显示 如果这看起来令人困惑,那么至少请告诉我一件简单的事情,那就是如何加载http网站192.168.100.6/feed?ID=sensor1&state=LOW,以便我的服

如何使用2节点MCU作为我的家庭wifi网络的服务器和客户端,因为该网络覆盖了我家的各个角落,可用于IOT设备

我的服务器端代码工作得很好,唯一的问题是按照我的假设,客户端代码。 将服务器和客户端与其中一个节点mcu的热点连接的过程在互联网上随处可见,但如何将两个节点mcu模块与家庭wifi连接,并仍用作服务器和客户端,未显示

如果这看起来令人困惑,那么至少请告诉我一件简单的事情,那就是如何加载http网站192.168.100.6/feed?ID=sensor1&state=LOW,以便我的服务器可以捕捉到这一点,并从链接向自己提供这些数据

我使用的代码:

对于客户端:

#包括
#包括
//#包括
字符串id=“传感器1”;
const char*ssid=“FFFFFFFF”;
常量字符*密码=“@@rkar777”;
常量字符*主机=”http://192.168.100.6";
无线客户端;
ip地址ip(192、168、100、19);
IP地址网关(192、168、10、1);
IP地址子网(255、255、255、0);
HTTPClient-http;
无效设置(){
//将安装代码放在此处,以便运行一次:
序列号开始(115200);
//
尤其是删除配置();
WiFi.persistent(假);
WiFi.模式(WiFi_STA);
WiFi.config(ip、网关、子网);
//
WiFi.begin(ssid,密码);
Serial.println(“连接”);
while(WiFi.status()!=WL_已连接){
连续打印(“.”);
延迟(500);
}
Serial.println(“”);
串行打印(“分配的Ip地址:”);
Serial.println(WiFi.localIP());
Serial.println(“got here1”);
延迟(1500);
http.begin(“192.168.100.6/feed?”);
int httpCode=http.GET();
如果(httpCode>0){
序列号。打印号(“是”);
}否则{
Serial.println(“再次拒绝”);
}
http.end();
if(客户端连接(主机,80)){
Serial.println(“到达这里”);
字符串url=“/feed?ID=sensor111&state=LOW”;
client.print(字符串(“GET”)+url+“HTTP/1.1\r\n”+“主机:”+Host+“\r\n”+“连接:保持活动\r\n\r\n”);
延迟(10);
Serial.println(“响应:”);
while(client.available()){
String line=client.readStringUntil('\r');
串行打印(行);
}
}
}
void循环(){
//将主代码放在此处,以便重复运行:
}
对于服务器:

#包括
#包括
#包括
#包括
//======================================================================热点的WIFI凭据==================================
const char*ssid=“FFFFFFFF”;
常量字符*密码=“@@rkar777”;
int max_连接=8;
//====================================================================================================
字符串URL;
int-httpCode;
管柱有效载荷;
字符串ID;
字符串状态;
//======================================================================定义对象======================================
//无线客户端;
ESP8266Web服务器(80);
HTTPClient-http;
//======================================================================定义热点的IP地址==================
ip地址ip(192、168、100、19);
IP地址网关(192、168、10、1);
IP地址子网(255、255、255、0);
//=====================================================================设置部分==================================================
无效设置(){
序列号开始(115200);
尤其是删除配置();
WiFi.persistent(假);
WiFi.模式(WiFi_STA);
WiFi.config(ip、网关、子网);
WiFi.begin(ssid,密码);//开始WiFi连接
Serial.println(“”);
//等待连接
while(WiFi.status()!=WL_已连接){
延迟(500);
连续打印(“.”);
}
Serial.println(“”);
串行打印(“连接到”);
序列号println(ssid);
串行打印(“IP地址:”);
Serial.println(WiFi.localIP());
server.on(“/”,handleroot);
server.on(“/feed”,feed);
server.begin();
}
//======================================================处理根页面================================================
void handleroot(){
send(200,“text/plain”,“hello”);
}
//==========================================================把手门传感器页面===========================================
无效馈送(){
字符串data2=server.arg(“state”);
字符串data1=server.arg(“ID”);
发送(200,“文本/普通”、“响应”);
Serial.println(data1+“=”+data2);
}
//=====================================================================循环===================================================
空循环(){
server.handleClient();
}
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
//#include<WiFi.h>
String id = "sensor 1";

const char* ssid = "FFFFFFFF";
const char* password = "@@rkar777";
const char* host = "http://192.168.100.6";
WiFiClient client;
IPAddress ip (192, 168, 100, 19);
IPAddress gateway (192, 168, 10, 1);
IPAddress subnet (255, 255, 255, 0);
HTTPClient http;

void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200);
    //
       ESP.eraseConfig();
  WiFi.persistent(false);
   WiFi.mode(WIFI_STA);
   WiFi.config(ip, gateway, subnet); 
  //
  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while(WiFi.status()!=WL_CONNECTED){
    Serial.print(".");
    delay(500);
    }
     Serial.println("");
    Serial.print("Ip address assigned: ");
    Serial.println(WiFi.localIP());
     Serial.println("got here1");
     delay(1500);
   http.begin("192.168.100.6/feed?");
   int httpCode =http.GET();
   if(httpCode>0){
    Serial.println("yessss");
    }else{
      Serial.println("no again");
      }
   http.end();
  
    if(client.connect(host,80)){
      Serial.println("got here");
      String url="/feed?ID=sensor111&state=LOW";
      client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: "+ host +"\r\n" + "Connection: keep-alive\r\n\r\n");
      delay(10);
      Serial .println("Response: ");
      while(client.available()){
      String line = client.readStringUntil('\r');
      Serial.print(line);
   
      }

    }
}

void loop() {
  // put your main code here, to run repeatedly:

}
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
#include <SoftwareSerial.h>

//======================================WIFI CREDENTIALS for Hotspot==================================
const char* ssid = "FFFFFFFF";
const char* password = "@@rkar777"; 
int max_connection = 8;
//====================================================================================================
String URL;
int httpCode;
String payload;
String ID;
String state;
//=============================================define the objects======================================
//WiFiClient client;

ESP8266WebServer server(80);
HTTPClient http;
//===============================================define the IP Address of the hotspot==================
IPAddress ip (192, 168, 100, 19);
IPAddress gateway (192, 168, 10, 1);
IPAddress subnet (255, 255, 255, 0);
//=========================================SETUP PART==================================================
void setup() {
  Serial.begin(115200);
   ESP.eraseConfig();
  WiFi.persistent(false);
   WiFi.mode(WIFI_STA);
   WiFi.config(ip, gateway, subnet); 
 WiFi.begin(ssid, password); //begin WiFi connection
  Serial.println("");
  
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/",handleroot);
  server.on("/feed",feed);
  server.begin();
}
//=====================================handle root page================================================
void handleroot(){

  server.send(200,"text/plain","hello");

}
//===================================handle door sensor page===========================================
void feed(){
  String data2 = server.arg("state");
  String data1 = server.arg("ID");
  server.send(200,"text/plain","Response");
  Serial.println(data1+"="+data2);
}

//==============================================LOOP===================================================
void loop (){

      server.handleClient();  
}