Hi all,
I don't know if this is the right tpoic group, but I think so, forgive me if not.
I have an nano and connected aESP-01 (ESP8266)
I created a simple gui on the remotexy website, with 1 button.
If that button is pressed the internal led turns on as long as you keep pressed the button.
So far so good.
Remotexy sketch: (read further below the sketch)
-- New project --
-
- This source code of graphical user interface *
- has been generated automatically by RemoteXY editor.*
- To compile this code using RemoteXY library 2.4.3 or later version *
- download by link http://remotexy.com/en/library/*
- To connect using RemoteXY mobile app by link Mobile App *
-
- for ANDROID 4.7.12 or later version;*
-
- for iOS 1.4.7 or later version;*
-
- This source code is free software; you can redistribute it and/or*
- modify it under the terms of the GNU Lesser General Public*
- License as published by the Free Software Foundation; either*
- version 2.1 of the License, or (at your option) any later version. *
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
*// RemoteXY select connection mode and include library *
#define REMOTEXY_MODE__ESP8266_SOFTSERIAL
#include <SoftwareSerial.h>
*#define REMOTEXY__DEBUGLOGS Serial *
#include <RemoteXY.h>
*// RemoteXY connection settings *
#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3
#define REMOTEXY_SERIAL_SPEED 9600
#define REMOTEXY_WIFI_SSID "mysid"
#define REMOTEXY_WIFI_PASSWORD "mypass"
#define REMOTEXY_SERVER_PORT 6377
*// RemoteXY configurate *
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
- { 255,1,0,0,0,13,0,11,13,0,*
- 1,0,11,10,12,12,2,31,88,0 };*
-
*// this structure defines all the variables and events of your control interface *
struct {
-
// input variables*
-
uint8_t button_1; // =1 if button pressed, else =0 *
-
// other variable*
-
uint8_t connect_flag; // =1 if wire connected, else =0 *
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_BUTTON_1 13
*void setup() *
{
- RemoteXY_Init (); *
Serial.begin(115200); -
*
- pinMode (PIN_BUTTON_1, OUTPUT);*
-
- // TODO you setup code*
-
}
*void loop() *
*{ *
- RemoteXY_Handler ();*
- digitalWrite(PIN_BUTTON_1, (RemoteXY.button_1==0)?LOW:HIGH);*
-
-
- // TODO you loop code*
- // use the RemoteXY structure for data transfer*
- // do not call delay() *
}
Now I want an webserver on the same hardware config, so that i can controll the led as in the example webserverled: (read further below the sketch)
WiFiEsp example: WebServerLed
-
- A simple web server that lets you turn on and of an LED via a web page.*
- This sketch will print the IP address of your ESP8266 module (once connected)*
- to the Serial monitor. From there, you can open that address in a web browser*
- to turn on and off the LED on pin 13.*
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2, 3); // RX, TX
#endif
char ssid[] = "mysid"; // your network SSID (name)
char pass[] = "mypass"; // your network password
int status = WL_IDLE_STATUS;
int ledStatus = LOW;
WiFiEspServer server(80);
// use a ring buffer to increase speed and reduce memory allocation
RingBuffer buf(8);
void setup()
{
-
pinMode(LED_BUILTIN, OUTPUT); // initialize digital pin LED_BUILTIN as an output.*
-
Serial.begin(115200); // initialize serial for debugging*
-
Serial1.begin(9600); // initialize serial for ESP module*
-
WiFi.init(&Serial1); // initialize ESP module*
-
// check for the presence of the shield*
-
if (WiFi.status() == WL_NO_SHIELD) {*
-
Serial.println("WiFi shield not present");*
-
// don't continue*
-
while (true);*
-
}*
-
// attempt to connect to WiFi network*
-
while (status != WL_CONNECTED) {*
-
Serial.print("Attempting to connect to WPA SSID: ");*
-
Serial.println(ssid);*
-
// Connect to WPA/WPA2 network*
-
status = WiFi.begin(ssid, pass);*
-
}*
-
Serial.println("You're connected to the network");*
-
printWifiStatus();*
-
-
// start the web server on port 80*
-
server.begin();*
}
void loop()
{
-
WiFiEspClient client = server.available(); // listen for incoming clients*
-
if (client) { // if you get a client,*
// Serial.println("New client"); // print a message out the serial port -
buf.init(); // initialize the circular buffer*
-
while (client.connected()) { // loop while the client's connected*
-
if (client.available()) { // if there's bytes to read from the client,*
-
char c = client.read(); // read a byte, then*
-
buf.push(c); // push it to the ring buffer*
-
// printing the stream to the serial monitor will slow down*
-
// the receiving of data from the ESP filling the serial buffer*
-
//Serial.write(c);*
-
*
-
// you got two newline characters in a row*
-
// that's the end of the HTTP request, so send a response*
-
if (buf.endsWith("\r\n\r\n")) {*
-
sendHttpResponse(client);*
-
break;*
-
}*
-
// Check to see if the client request was "GET /H" or "GET /L":*
-
if (buf.endsWith("GET /H")) {*
// Serial.println("Turn led ON");
-
ledStatus = HIGH;*
-
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)*
-
}*
-
else if (buf.endsWith("GET /L")) {*
// Serial.println("Turn led OFF");
-
ledStatus = LOW;*
-
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW*
-
}*
-
}*
- }*
-
- // close the connection*
- client.stop();*
// Serial.println("Client disconnected"); - }*
}
void sendHttpResponse(WiFiEspClient client)
{
- // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)*
- // and a content-type so the client knows what's coming, then a blank line:*
- client.print(*
-
"HTTP/1.1 200 OK\r\n"*
-
"Content-Type: text/html\r\n"*
-
"Connection: close\r\n" // the connection will be closed after completion of the response*
-
"Refresh: 20\r\n" // refresh the page automatically every 20 sec*
-
"\r\n");*
-
- // the content of the HTTP response follows the header:*
- client.print("The LED is ");*
- client.print(ledStatus);*
- client.print("
\r\n"* -
"<br>\r\n"*
-
"Click <a href=\"/H\">here</a> turn the LED on<br>\r\n"*
-
"Click <a href=\"/L\">here</a> turn the LED off<br>\r\n");*
-
- // The HTTP response ends with another blank line:*
- client.println();*
}
void printWifiStatus()
{
-
// print the SSID of the network you're attached to*
-
Serial.print("SSID: ");*
-
Serial.println(WiFi.SSID());*
-
// print your WiFi shield's IP address*
-
IPAddress ip = WiFi.localIP();*
-
Serial.print("IP Address: ");*
-
Serial.println(ip);*
-
// Serial.println(WiFi.getMode());*
-
// print where to go in the browser*
-
Serial.println();*
-
Serial.print("To see this page in action, open a browser to http://");*
-
Serial.println(ip);*
-
Serial.println();*
}
So I want to merge these 2 sketches as 1.
But if I do so, the remotexy app on the phone cannot connect.
I guess since I try double on connecting my wifi (in remotexy.init() and in the void setup on the other sketch.
Is there anybody who knows how to have both remotexy and a webserver on the nano / esp8266 config ? THe hardware cannot be changes as this is a test of the hardware in my Jacuzzi.
Thx for any help