我正在设计用于操作DTH的无线遥控器。我正在使用ESP8266 WiFi模块作为服务器和接收器。服务器和接收器都将连接到家庭路由器。我通过Arduino IDE网站和示例上的可用信息编写了一小段代码。
我通过服务器解码了IR信号。仅将“开/关”按钮代码发送给客户端。在客户端收到它并显示在串行监视器上。一切正常,直到我在客户端ESP模块中添加了 irsend 库。当我添加该库并将代码转储到ESP中后,它开始重置并出现以下错误:
wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v951aeffa
~ld
.
ets Jan 8 2013,rst cause:4, boot mode:(3,7)
这是服务器ESP模块的代码
#include <SPI.h>
#include <ESP8266WiFi.h>
#ifndef UNIT_TEST
#include <Arduino.h>
#endif
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
char ssid[] = "RedmiNote5"; // SSID of your home WiFi
char pass[] = "Dheeraj@247"; // password of your home WiFi
WiFiServer server(80);
IPAddress ip(192, 168, 43, 80); // IP address of the server
IPAddress gateway(192,168,43,1); // gateway of your network
IPAddress subnet(255,255,255,0); // subnet mask of your network
unsigned long int x=0;
// an IR detector/demodulator is connected to GPIO pin 2
uint16_t RECV_PIN = 14;//2
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(115200);
irrecv.enableIRIn(); // Start the receiver
WiFi.config(ip, gateway, subnet); // forces to use the fix IP
WiFi.begin(ssid, pass); // connects to the WiFi router
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.print("WiFi Connected \n");
server.begin(); // starts the server
}
void loop() {
if (irrecv.decode(&results)) {
//serialPrintUint64(results.value, 16);
//Serial.println('\n');
x = results.value;
if(x == 12582924){
WiFiClient client = server.available();
client.println(x); // sends the answer to the client
client.println('\r');
//client.flush(); //no need to uncomment this, this causes an issue.
}
Serial.println( x);
x=0;
Serial.println('\n');
irrecv.resume(); // Receive the next value
}
}
这是客户端ESP模块的代码
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
//const uint16_t kIrLed = 7; // ESP8266 GPIO pin to use. Recommended: 4
(D2). GPIO5
IRsend irsend(7); // Set the GPIO to be used to sending the message.
//int x =0;
byte ledPin = 2;
char ssid[] = "RedmiNote5"; // SSID of your home WiFi//
char pass[] = "Dheeraj@247"; // password of your home WiFi
unsigned long askTimer = 0;
IPAddress server(192,168,43,80); // the fix IP address of the server
WiFiClient client;
void setup() {
Serial.begin(115200); // only for debug
WiFi.begin(ssid, pass); // connects to the WiFi router
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
irsend.begin();
delay(500);
}
Serial.println("Connected to wifi");
Serial.print("Status: "); Serial.println(WiFi.status()); // Network parameters
Serial.print("IP: "); Serial.println(WiFi.localIP());
Serial.print("Subnet: "); Serial.println(WiFi.subnetMask());
Serial.print("Gateway: "); Serial.println(WiFi.gatewayIP());
Serial.print("SSID: "); Serial.println(WiFi.SSID());
Serial.print("Signal: "); Serial.println(WiFi.RSSI());
pinMode(ledPin, OUTPUT);
}
void loop () {
client.connect(server, 80); // Connection to the server
digitalWrite(ledPin, LOW); // to show the communication only
//Serial.println(".");
String answer = client.readStringUntil('\r'); // receives the answer
from the sever //
Serial.println("from server: " + answer);
unsigned long int x = strtoul(answer.c_str(), NULL, 10);
if(x==12582924){
Serial.println(x);
Serial.println("I am in the loop");
x = 0;
}
//irsend.sendRC6(answer, 21);
delay(20);
digitalWrite(ledPin, HIGH);
delay(100);
}
我请所有经验丰富的人来指导我解决这个问题。
谢谢。