Giter Club home page Giter Club logo

esp-131gpio's People

Contributors

garymueller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

esp-131gpio's Issues

stuck in a loop

Not sure what I'm doing wrong, after uploading the device just seems to be stuck in a loop rebooting with an exception epc1=0x40202e89.

Serial output below:
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v0005a0d0
~ld
{"network":{"hostname":"esps-98237f","ssid":"MySSID","password":"MyPassword","static":false,"static_ip":"192.168.1.100","static_netmask":"255.255.255.0","static_gateway":"192.168.1.1","access_point":true},"E131":{"multicast":"true","universe":1,"channel_offset":0},"GPIO":{"digital":"true","digital_threshold":127,"digital_lowlevel":false}}

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (0):
epc1=0x40202e89 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

stack>>>

ctx: cont
sp: 3ffffd10 end: 3fffffc0 offset: 0190
3ffffea0: 3ffe88b7 3ffef1f4 3ffef1e0 40202e89
3ffffeb0: 3fff03e4 3ffef1e0 00000000 00000100
3ffffec0: feefeffe feefeffe feefeffe 3fff0c7c
3ffffed0: 00000020 000000fc 3fff0004 40211b08
3ffffee0: 3fffff20 00000000 3fff097c 000000f0
3ffffef0: feefeffe feefeffe 00000578 00000578
3fffff00: 000000f0 3fff0004 3ffefffc 4020ff25
3fffff10: 00000578 40218dd8 00000000 000003e8
3fffff20: 3fff0a7c 00000000 00000000 00000000
3fffff30: 00000000 00000000 00000000 3ffef48c
3fffff40: 00000000 000b000f 00000000 3fff04b4
3fffff50: 3ffef1e0 00000001 3ffef28c 3ffef404
3fffff60: 00000000 3fff0004 3ffefffc 4020ffbe
3fffff70: 00000000 3ffe8ca5 3ffef48c 3ffef404
3fffff80: 3fffdad0 3ffe8ca5 00000001 40202ea4
3fffff90: 3fffdad0 3ffe8ca5 3ffef28c 40204461
3fffffa0: feefeffe 00000000 3ffef3f0 4020e864
3fffffb0: feefeffe feefeffe 3ffe85e4 40100d81
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

upgrade esp8266 library to current version (3.02)

There are currently runtime issues with the firmware when runing with the latest esp8266 library (3.02). Issues include #4 and #5. Issues include firmware not loading or connecting to wifi. We should update the firmware to be able to support the latest esp8266 library.

Hint: The previous stack trace indicates issues when initializing SPIFFS. We should update the file system to littlefs and see if that fixes the issue. See https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html

Relay is reversed

Apparently my relay is in reverse. Turning it on in the app turns off the relay turning it off turns on the relay. Any idea how I could reverse this?

xlights output

Greetings,

Xlights does not turn off my esp8266 relay controller before running sequence!

I have another single relay controller that I loaded last year and it works perfectly! It stays on when you do a hard reset which is good and when I run xlights and hit the bulb button it turns off until I run the sequence! I cant remember for the life of me which code I loaded onto it but is has the same web interface as your code! Cant find that code to replicate another one with 4 relays on it!

Your code is not turning off when I hit the light bulb on xlights! It works well otherwise!
I would like it to default to on when booted up and then have xlights turn it off like my WLED controllers do!
Everything needs to go dark before my sequence starts!

If you have some insight it would be greatly appreciated!

ESPAsyncE131-master/RingBuf.h:50:77: error: extended character ” is not valid in an identifier

Hi Garymueller,

I use your code last year for my christmas light, it was great.
I want to had some more and i try to flash a new wemos D1 mini but this time I have this return about buf :

In file included from C:\Users\jpbet\Documents\Arduino\libraries\ESPAsyncE131-master/ESPAsyncE131.h:37,
from C:\Users\jpbet\Documents\Arduino\ESP-131GPIO\ESP-131GPIO.ino:4:
C:\Users\jpbet\Documents\Arduino\libraries\ESPAsyncE131-master/RingBuf.h:50:18: error: extended character “ is not valid in an identifier
50 | #warning “This library only fully supports AVR and ESP8266 Boards.”
| ^
C:\Users\jpbet\Documents\Arduino\libraries\ESPAsyncE131-master/RingBuf.h:50:77: error: extended character ” is not valid in an identifier
50 | #warning “This library only fully supports AVR and ESP8266 Boards.”
| ^
Plusieurs bibliothèque trouvées pour "ESPAsyncE131.h"
Utilisé : C:\Users\jpbet\Documents\Arduino\libraries\ESPAsyncE131-master
Non utilisé : C:\Users\jpbet\Documents\Arduino\libraries\ESP_Async_E1.31
exit status 1
Erreur de compilation pour la carte LOLIN(WEMOS) D1 R2 & mini

Could you help me ?

Thanks a lot

//https://github.com/garymueller/ESP-131GPIO

#include <ESP8266WiFi.h>
#include <ESPAsyncE131.h>
#include <ESPAsyncWebServer.h>
#include <ESPAsyncDNSServer.h>
#include <LittleFS.h>
#include <ArduinoJson.h>
#include

using namespace std;

// ***** USER SETUP STUFF *****
String ssid = "Freedelapassion"; // replace with your SSID.
String password = "tokaavai"; // replace with your password.

String CONFIG_FILE = "Config.json";
DynamicJsonDocument Config(1024);
AsyncWebServer server(80);
AsyncDNSServer dnsServer;
ESPAsyncE131 e131;

//for Wemos D1 R1 pins are 16,5,4,14,12,13,0,2
//vector GpioVector{16,5,4,14,12,13,0,2};
//for Wemos D1 R2 pins are 16,5,4,0,2,14,12,13
vector GpioVector{16,5,4,0,2,14,12,13};
int DigitalOn = HIGH;
int DigitalOff = LOW;

//Forward Declarations
String WebReplace(const String& var);

bool LoadConfig();
void SaveConfig(AsyncWebServerRequest* request);

void InitGpio();
void InitWifi();
void Init131();
void InitWeb();

/*

  • Sets up the initial state and starts sockets
    */
    void setup() {
    Serial.begin(115200);
    delay(500);
    Serial.println("==============================");
    Serial.println("Start Setup");

LoadConfig();

InitGpio();

InitWifi();

Init131();

InitWeb();

Serial.println("Completed setup. Starting loop");
Serial.println("==============================");
}

/*

  • Main Event Loop
    */
    void loop() {
    e131_packet_t packet;
    bool Digital = Config["GPIO"]["digital"].as();
    int DigitalThreshold = Config["GPIO"]["digital_threshold"].as();
    int ChannelOffset = Config["E131"]["channel_offset"].as();

while(!e131.isEmpty()) {
e131.pull(&packet); // Pull packet from ring buffer
uint16_t num_channels = htons(packet.property_value_count) - 1;

for(int GpioIndex = 0, ChannelIndex = ChannelOffset;
    GpioIndex < GpioVector.size() && ChannelIndex < num_channels; 
    ++GpioIndex, ++ChannelIndex) {
  
  uint16_t data = packet.property_values[ChannelIndex+1];
  if(Digital) {
    digitalWrite(GpioVector[GpioIndex], (data >= DigitalThreshold) ? DigitalOn : DigitalOff);
  } else {
    analogWrite(GpioVector[GpioIndex], data);
  }
  //Serial.printf("%d:%d:%d; ",GpioIndex,data,(data > DigitalThreshold) ? DigitalOn : DigitalOff);
}//for loop
//Serial.println("");

}//! empty
}// end void loop

/*

  • InitGpio
    */
    void InitGpio()
    {
    //initialize GPIO pins
    for(int i = 0; i < GpioVector.size(); ++i) {
    pinMode(GpioVector[i], OUTPUT);
    digitalWrite(GpioVector[i], DigitalOff);
    }
    }

/*

  • Loads the config from SPPS into the Config variable
    */
    bool LoadConfig()
    {
    // Initialize LittleFS
    if(!LittleFS.begin()){
    Serial.println("An Error has occurred while mounting LittleFS");
    return false;
    }

File file = LittleFS.open(CONFIG_FILE, "r");
if (!file) {
//First Run, setup defaults
Config["network"]["hostname"] = "esps-" + String(ESP.getChipId(), HEX);
Config["network"]["ssid"] = ssid;
Config["network"]["password"] = password;
Config["network"]["static"] = false;
Config["network"]["static_ip"] = "192.168.1.100";
Config["network"]["static_netmask"] = "255.255.255.0";
Config["network"]["static_gateway"] = "192.168.1.1";
Config["network"]["access_point"] = true;

Config["E131"]["multicast"] = "true";
Config["E131"]["universe"] = 1;
Config["E131"]["channel_offset"] = 0;

Config["GPIO"]["digital"] = "true";
Config["GPIO"]["digital_threshold"] = 127;
Config["GPIO"]["digital_lowlevel"] = false;

} else {
Serial.println("Loading Configuration File");
deserializeJson(Config, file);
}

if(Config["GPIO"]["digital_lowlevel"].as()) {
DigitalOn = LOW;
DigitalOff = HIGH;
} else {
DigitalOn = HIGH;
DigitalOff = LOW;
}

serializeJson(Config, Serial);Serial.println();
return true;
}

void SaveConfig(AsyncWebServerRequest* request)
{
Serial.println("Saving Configuration File");

//debug
int params = request->params();
for(int i=0;i<params;i++){
AsyncWebParameter* p = request->getParam(i);
Serial.printf("Param: %s, %s\n", p->name().c_str(), p->value().c_str());
}

//Validate Config

Config["network"]["hostname"] = request->getParam("hostname",true)->value();
Config["network"]["ssid"] = request->getParam("ssid",true)->value();
Config["network"]["password"] = request->getParam("password",true)->value();
//checkbox status isnt always included if toggled off
Config["network"]["static"] =
(request->hasParam("static",true) && (request->getParam("static",true)->value() == "on"));
Config["network"]["static_ip"] = request->getParam("static_ip",true)->value();
Config["network"]["static_netmask"] = request->getParam("static_netmask",true)->value();
Config["network"]["static_gateway"] = request->getParam("static_gateway",true)->value();
Config["network"]["access_point"] =
(request->hasParam("access_point",true) && (request->getParam("access_point",true)->value() == "on"));

//checkbox status isnt always included if toggled off
Config["E131"]["multicast"] =
(request->hasParam("multicast",true) && (request->getParam("multicast",true)->value() == "on"));
Config["E131"]["universe"] = request->getParam("universe",true)->value();
Config["E131"]["channel_offset"] = request->getParam("channel_offset",true)->value();

//checkbox status isnt always included if toggled off
Config["GPIO"]["digital"] =
(request->hasParam("digital",true) && (request->getParam("digital",true)->value() == "on"));
Config["GPIO"]["digital_threshold"] = request->getParam("digital_threshold",true)->value();
Config["GPIO"]["digital_lowlevel"] =
(request->hasParam("digital_lowlevel",true) && (request->getParam("digital_lowlevel",true)->value() == "on"));

File file = LittleFS.open(CONFIG_FILE, "w");
if(file) {
serializeJson(Config, file);
serializeJson(Config, Serial);
}

request->send(200);
ESP.restart();
}

/*

  • Initialiaze Wifi (DHCP/STATIC and Access Point)
    */
    void InitWifi()
    {
    // Switch to station mode and disconnect just in case
    WiFi.mode(WIFI_STA);
    WiFi.disconnect();

WiFi.hostname(Config["network"]["hostname"].as<const char*>());

//configure Static/DHCP
if(Config["network"]["static"].as()) {
IPAddress IP; IP.fromString(Config["network"]["static_ip"].as());
IPAddress Netmask; Netmask.fromString(Config["network"]["static_netmask"].as());
IPAddress Gateway; Gateway.fromString(Config["network"]["static_gateway"].as());

if(WiFi.config(IP, Netmask, Gateway)) {
  Serial.println("Successfully configured static IP");
} else {
  Serial.println("Failed to configure static IP");
}

} else {
Serial.println("Connecting with DHCP");
}

//Connect
int Timeout = 15000;
WiFi.begin(Config["network"]["ssid"].as(), Config["network"]["password"].as());
if(WiFi.waitForConnectResult(Timeout) != WL_CONNECTED) {
if(Config["network"]["access_point"].as()) {
Serial.println("*** FAILED TO ASSOCIATE WITH AP, GOING SOFTAP ");
WiFi.mode(WIFI_AP);
WiFi.softAP(Config["network"]["hostname"].as());
dnsServer.start(53, "
", WiFi.softAPIP());
} else {
Serial.println(F("
* FAILED TO ASSOCIATE WITH AP, REBOOTING ***"));
ESP.restart();
}
} else {
Serial.printf("Connected as %s\n",WiFi.localIP().toString().c_str());
}

WiFi.printDiag(Serial);
}

void Init131()
{
if(Config["E131"]["multicast"].as()) {
Serial.printf("Initializing Multicast with universe <%d>\n",Config["E131"]["universe"].as());
e131.begin(E131_MULTICAST, Config["E131"]["universe"]);
} else {
Serial.println("Initializing Unicast");
e131.begin(E131_UNICAST);
}
}

/*

  • Initializes the webserver
    */
    void InitWeb()
    {
    //enables redirect to /index.html on AP connection
    server.onNotFound([](AsyncWebServerRequest *request){
    request->send(LittleFS, "/index.html", String(), false, WebReplace);
    });

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(LittleFS, "/index.html", String(), false, WebReplace);
});
server.on("/favicon.ico", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(LittleFS, "/favicon.png", "image/png");
});
server.on("/SaveConfig", HTTP_POST, [](AsyncWebServerRequest *request){
SaveConfig(request);
});
server.on("/SetRelay", HTTP_GET, [](AsyncWebServerRequest *request){
int relay = request->getParam("relay")->value().toInt();
if(relay<0 || relay >= GpioVector.size()) {
Serial.println("SetRelay - Index out of range");
return;
}
digitalWrite(GpioVector[relay], (request->getParam("checked")->value() == "true") ? DigitalOn : DigitalOff);
request->send(200);
});

server.begin();
}

/*

  • WebReplace:
  • Substitutes variables inside of the html
    */
    String WebReplace(const String& var)
    {
    //Status Page
    if (var == "SSID") {
    return (String)WiFi.SSID();
    } else if (var == "HOSTNAME") {
    return (String)WiFi.hostname();
    } else if (var == "IP") {
    if(WiFi.getMode() == WIFI_AP) {
    return WiFi.softAPIP().toString();
    } else {
    return WiFi.localIP().toString();
    }
    } else if (var == "MAC") {
    return (String)WiFi.macAddress();
    } else if (var == "RSSI") {
    return (String)WiFi.RSSI();
    } else if (var == "HEAP") {
    return (String)ESP.getFreeHeap();
    } else if (var == "UPTIME") {
    return String(millis());
    } else if (var == "UNIVERSE") {
    return Config["E131"]["universe"];
    } else if (var == "PACKETS") {
    return (String)e131.stats.num_packets;
    } else if (var == "PACKET_ERR") {
    return (String)e131.stats.packet_errors;
    } else if (var == "LAST_IP") {
    return e131.stats.last_clientIP.toString();

//Configuration Page
} else if (var == "CONFIG_HOSTNAME") {
return Config["network"]["hostname"];
} else if (var == "CONFIG_SSID") {
return Config["network"]["ssid"];
} else if (var == "CONFIG_PASSWORD") {
return Config["network"]["password"];
} else if (var == "CONFIG_AP") {
if(Config["network"]["access_point"].as())
return "checked";
else
return "";
} else if (var == "CONFIG_STATIC") {
if(Config["network"]["static"].as())
return "checked";
else
return "";
} else if (var == "CONFIG_STATIC_IP") {
return Config["network"]["static_ip"];
} else if (var == "CONFIG_STATIC_NETMASK") {
return Config["network"]["static_netmask"];
} else if (var == "CONFIG_STATIC_GATEWAY") {
return Config["network"]["static_gateway"];
} else if (var == "CONFIG_MULTICAST") {
if(Config["E131"]["multicast"].as())
return "checked";
else
return "";
} else if (var == "CONFIG_UNIVERSE") {
return Config["E131"]["universe"];
} else if (var == "CONFIG_CHANNEL_OFFSET") {
return Config["E131"]["channel_offset"];
} else if (var == "CONFIG_DIGITAL") {
if(Config["GPIO"]["digital"].as())
return "checked";
else
return "";
} else if (var == "CONFIG_THRESHOLD") {
return Config["GPIO"]["digital_threshold"];
} else if (var == "CONFIG_LOWLEVEL") {
if(Config["GPIO"]["digital_lowlevel"].as())
return "checked";
else
return "";

//Relay Page
} else if (var == "RELAYS") {
String Relays = "";
for(int i = 0; i < GpioVector.size(); ++i) {
Relays += "Relay "+String(i+1)+" ("+GpioVector[i]+")";
Relays += " <label class="switch">";
Relays += " <input type="checkbox" ";
if(digitalRead(GpioVector[i]) == DigitalOn) {
Relays += "checked";
}
Relays += " onclick="fetch('SetRelay?relay="+String(i)+"&checked='+this.checked);">";
Relays += " <span class="slider round">";
Relays += "";
Relays += "

";
}
return Relays;
}

return var;
}

Web Page Not Responsive

First, thank you so much for sharing this. I'm very excited about getting it working.

I have downloaded everything, installed all libraries and tools, compiled and uploaded without error. The device is pulling a DHCP address (x.x.x.51). I can ping the address without problem. However, I cannot get the web page to come up. The browser (Chrome) just says it cannot be found. Any suggestions on where to start? The only thing I have changed in the config is the SSID and password, and I can see that it is connected to the router.

PWM Support

Tested your code on 8 relays! Works great thanks! As far as PWM goes how does one implement it? I have a 2 channel PWM dimmer module and was looking for a starting point for testing.

Thanks in advance.

How to control from XLights?

Hi,

TLDR:
Support question is how to add this ESP with channel relay to Xlights and how to control the individual channels, for example how to turn on channel 1 and 3 but turn of channel 5 and 8


Last year i started using xlights for lights in combination with home assistant for some esp devices like fog and water pump sprayers. Doing the lights from xlights sequence and the fog /water from home assistent gives a mismatch in timing.

The reason it’s esphome based is because it are small fog makers/water pumps that I use it in the Lemax/Luville Christmas village my girlfriend every years build. Last year we tried to make a watershow in the village like it’s in a theme park nearby (https://youtu.be/dzQdW_HgRlA) also see the attached images from last year.

From several facebooks groups I was pointed to this git to make those devices also available in Xlights so I can make a large sequence on time there with lights and other devices. We are now preparing the ideas for this year so that's why I was hoping you could point in how to add this to xlights or maybe even add it to the readme? :)

Devices I use now with esp / esp + channel relay All below devices are just on/off so powered or not powered
Example waterpumps i have used:

Example fog makers i have used:

Example non smart lights (just on/off)

Some pictures to illustrate the idea:
unknown
WhatsApp_Image_2020-10-22_at_11 46 35_1
WhatsApp_Image_2020-10-23_at_15 21 48

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.