Axa remote script with softserial
Posted: Saturday 12 December 2020 16:50
I control my window opener (axa remote) with this script:
But because of a change in my hardware I want to use the softwareserial. So I change my script to:
I get an error when compiling in the arduino IDE:
and I changed everywhere serial to softserial. I am not very good at programming so I don't see what the problem here is. Can someone get me on the right track?
Code: Select all
/*
* This sketch reads a command through a http connection
* depending on the text received it will send open, stop or close
* commands to the Esp8266. the ESP8266 is connected to the Axa Remote 2.0 electric window opener
*/
#include <ESP8266WiFi.h>
const char* ssid = "xxx";
const char* password = "xxxx";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
Serial.begin(19200,SERIAL_8N1);
delay(10);
// Connect to WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
// Start the server
server.begin();
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
client.flush();
// Match the request
int val;
if (req.indexOf("/open") != -1)
open_axa();
else
if (req.indexOf("/close") != -1)
close_axa();
else if (req.indexOf("/stop") != -1)
stop_axa();
else {
Serial.println("invalid request");
client.stop();
return;
}
}
void open_axa() {
Serial.print("O");
delay(20);
Serial.print("P");
delay(20);
Serial.print("E");
delay(20);
Serial.print("N");
delay(20);
Serial.println("\r");
delay(200);
Serial.print("O");
delay(20);
Serial.print("P");
delay(20);
Serial.print("E");
delay(20);
Serial.print("N");
delay(20);
Serial.println("\r");
delay(200);
Serial.print("O");
delay(20);
Serial.print("P");
delay(20);
Serial.print("E");
delay(20);
Serial.print("N");
delay(20);
Serial.println("\r");
delay(2000);
}
void close_axa() {
Serial.print("C");
delay(20);
Serial.print("L");
delay(20);
Serial.print("O");
delay(20);
Serial.print("S");
delay(20);
Serial.print("E");
delay(20);
Serial.println("\r");
delay(2000);
Serial.print("C");
delay(20);
Serial.print("L");
delay(20);
Serial.print("O");
delay(20);
Serial.print("S");
delay(20);
Serial.print("E");
delay(20);
Serial.println("\r");
delay(2000);
Serial.print("C");
delay(20);
Serial.print("L");
delay(20);
Serial.print("O");
delay(20);
Serial.print("S");
delay(20);
Serial.print("E");
delay(20);
Serial.println("\r");
delay(2000);
}
void stop_axa() {
Serial.print("S");
delay(20);
Serial.print("T");
delay(20);
Serial.print("O");
delay(20);
Serial.print("P");
delay(20);
Serial.println("\r");
Serial.print("S");
delay(20);
Serial.print("T");
delay(20);
Serial.print("O");
delay(20);
Serial.print("P");
delay(20);
Serial.println("\r");
Serial.print("S");
delay(20);
Serial.print("T");
delay(20);
Serial.print("O");
delay(20);
Serial.print("P");
delay(20);
Serial.println("\r");
}Code: Select all
/*
* This sketch reads a command through a http connection
* depending on the text received it will send open, stop or close
* commands to the Esp8266. the ESP8266 is connected to the Axa Remote 2.0 electric window opener
*/
#include <SoftwareSerial.h> // For Swapping TX/RX
#define rxPin 1
#define txPin 3
#define MAX_MSG_LEN (128) // maximum MQTT recieved message length
const byte numChars = 128; // maximum SERIAL recieved message length
char receivedChars[numChars]; // an array to store the received message
const byte numCode = 4; // maximum SERIAL recieved message length
char receivedCode[numCode]; // an array to store the received code
boolean newData = false;
SoftwareSerial SoftSerial(rxPin, txPin); // Software serial
#include <ESP8266WiFi.h>
const char* ssid = "xxx";
const char* password = "xxxx";
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);
void setup() {
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
SoftSerial.begin(19200,SWSERIAL_8N1);
delay(10);
// Connect to WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
// Start the server
server.begin();
}
void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
while(!client.available()){
delay(1);
}
// Read the first line of the request
String req = client.readStringUntil('\r');
client.flush();
// Match the request
int val;
if (req.indexOf("/open") != -1)
open_axa();
else
if (req.indexOf("/close") != -1)
close_axa();
else if (req.indexOf("/stop") != -1)
stop_axa();
else {
SoftSerial.println("invalid request");
client.stop();
return;
}
}
void open_axa() {
Softserial.print("O");
delay(20);
SoftSerial.print("P");
delay(20);
SoftSerial.print("E");
delay(20);
SoftSerial.print("N");
delay(20);
SoftSerial.println("\r");
delay(200);
SoftSerial.print("O");
delay(20);
SoftSerial.print("P");
delay(20);
SoftSerial.print("E");
delay(20);
SoftSerial.print("N");
delay(20);
SoftSerial.println("\r");
delay(200);
SoftSerial.print("O");
delay(20);
SoftSerial.print("P");
delay(20);
SoftSerial.print("E");
delay(20);
SoftSerial.print("N");
delay(20);
SoftSerial.println("\r");
delay(2000);
}
void close_axa() {
SoftSerial.print("C");
delay(20);
SoftSerial.print("L");
delay(20);
SoftSerial.print("O");
delay(20);
SoftSerial.print("S");
delay(20);
SoftSerial.print("E");
delay(20);
SoftSerial.println("\r");
delay(2000);
SoftSerial.print("C");
delay(20);
SoftSerial.print("L");
delay(20);
SoftSerial.print("O");
delay(20);
SoftSerial.print("S");
delay(20);
SoftSerial.print("E");
delay(20);
SoftSerial.println("\r");
delay(2000);
SoftSerial.print("C");
delay(20);
SoftSerial.print("L");
delay(20);
SoftSerial.print("O");
delay(20);
SoftSerial.print("S");
delay(20);
SoftSerial.print("E");
delay(20);
SoftSerial.println("\r");
delay(2000);
}
void stop_axa() {
SoftSerial.print("S");
delay(20);
SoftSerial.print("T");
delay(20);
SoftSerial.print("O");
delay(20);
SoftSerial.print("P");
delay(20);
SoftSerial.println("\r");
SoftSerial.print("S");
delay(20);
SoftSerial.print("T");
delay(20);
SoftSerial.print("O");
delay(20);
SoftSerial.print("P");
delay(20);
SoftSerial.println("\r");
SoftSerial.print("S");
delay(20);
SoftSerial.print("T");
delay(20);
SoftSerial.print("O");
delay(20);
SoftSerial.print("P");
delay(20);
SoftSerial.println("\r");
}What do I change in the second script? I add:Softserial' was not declared in this scope
Code: Select all
#include <SoftwareSerial.h> // For Swapping TX/RX
#define rxPin 1
#define txPin 3
#define MAX_MSG_LEN (128) // maximum MQTT recieved message length
const byte numChars = 128; // maximum SERIAL recieved message length
char receivedChars[numChars]; // an array to store the received message
const byte numCode = 4; // maximum SERIAL recieved message length
char receivedCode[numCode]; // an array to store the received code
boolean newData = false;
SoftwareSerial SoftSerial(rxPin, txPin); // Software serial