mirror of
				https://github.com/HendrikRauh/dmx-interface.git
				synced 2025-11-04 08:51:02 +00:00 
			
		
		
		
	Add ethernet/wifi switch
This commit is contained in:
		
							parent
							
								
									13055b4b32
								
							
						
					
					
						commit
						3ce1df2136
					
				
					 2 changed files with 96 additions and 13 deletions
				
			
		| 
						 | 
				
			
			@ -15,4 +15,5 @@ framework = arduino
 | 
			
		|||
lib_deps = 
 | 
			
		||||
	hideakitai/ArtNet @ ^0.8.0
 | 
			
		||||
	bblanchon/ArduinoJson @ ^7.2.0
 | 
			
		||||
	me-no-dev/ESP Async WebServer
 | 
			
		||||
	me-no-dev/ESP Async WebServer@^1.2.4
 | 
			
		||||
	arduino-libraries/Ethernet @ ^2.0.2
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										102
									
								
								src/main.cpp
									
										
									
									
									
								
							
							
						
						
									
										102
									
								
								src/main.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,8 +1,17 @@
 | 
			
		|||
#include <ArtnetWiFi.h>
 | 
			
		||||
// #include <ArtnetEther.h>
 | 
			
		||||
 | 
			
		||||
#include <ArtnetEther.h>
 | 
			
		||||
#include <ArduinoJson.h>
 | 
			
		||||
#include "ESPDMX.h"
 | 
			
		||||
#include "SPI.h"
 | 
			
		||||
 | 
			
		||||
#ifdef ESP32
 | 
			
		||||
#include <WiFi.h>
 | 
			
		||||
#include <AsyncTCP.h>
 | 
			
		||||
#elif defined(ESP8266)
 | 
			
		||||
#include <ESP8266WiFi.h>
 | 
			
		||||
#include <ESPAsyncTCP.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <ESPAsyncWebServer.h>
 | 
			
		||||
#include <SPIFFS.h>
 | 
			
		||||
#include <Preferences.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -10,6 +19,15 @@
 | 
			
		|||
Preferences config;
 | 
			
		||||
DMXESPSerial dmx;
 | 
			
		||||
 | 
			
		||||
// Ethernet stuff
 | 
			
		||||
#define SCK       39
 | 
			
		||||
#define SS        33
 | 
			
		||||
#define MOSI      35
 | 
			
		||||
#define MISO      37
 | 
			
		||||
#define SPI_FREQ  32000000
 | 
			
		||||
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
 | 
			
		||||
enum ethTypes {AP = 1, STA = 2, ETH = 3}; // to be changed to Raffaels(TM) enum
 | 
			
		||||
 | 
			
		||||
AsyncWebServer server(80);
 | 
			
		||||
 | 
			
		||||
ArtnetWiFi artnet;
 | 
			
		||||
| 
						 | 
				
			
			@ -18,7 +36,11 @@ uint8_t data[size];
 | 
			
		|||
 | 
			
		||||
void setup()
 | 
			
		||||
{
 | 
			
		||||
    // Serial console
 | 
			
		||||
    Serial.begin(9600);
 | 
			
		||||
    Serial.print("Start DMX-Interface");
 | 
			
		||||
    delay(1000);
 | 
			
		||||
    Serial.println("...");
 | 
			
		||||
 | 
			
		||||
    config.begin("dmx", false);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -35,22 +57,82 @@ void setup()
 | 
			
		|||
    const IPAddress gateway(192, 168, 1, 1);
 | 
			
		||||
    const IPAddress subnet(255, 255, 255, 0);
 | 
			
		||||
 | 
			
		||||
    // WiFi stuff
 | 
			
		||||
    // WiFi.begin(ssid, pwd);
 | 
			
		||||
 | 
			
		||||
    // Initialize Interface connection type - to be changed to Raffaels(TM) enum
 | 
			
		||||
    ethTypes ethType;
 | 
			
		||||
    ethType = ETH;
 | 
			
		||||
 | 
			
		||||
    switch (ethType) 
 | 
			
		||||
    {
 | 
			
		||||
    case STA:
 | 
			
		||||
        Serial.println("Initialize as WiFi-STA");
 | 
			
		||||
        WiFi.begin(ssid, pwd);
 | 
			
		||||
        WiFi.config(ip, gateway, subnet);
 | 
			
		||||
        while (WiFi.status() != WL_CONNECTED) {
 | 
			
		||||
            Serial.print(".");
 | 
			
		||||
            delay(500);
 | 
			
		||||
        }
 | 
			
		||||
        Serial.print("WiFi connected, IP = ");
 | 
			
		||||
        Serial.println(WiFi.localIP());
 | 
			
		||||
        break;
 | 
			
		||||
    case ETH:
 | 
			
		||||
        Serial.println("Initialize as ETH");
 | 
			
		||||
    
 | 
			
		||||
        WiFi.mode(WIFI_STA); // Trotzdem wegen WebServer
 | 
			
		||||
        SPI.begin(SCK, MISO, MOSI, SS);
 | 
			
		||||
        SPI.setFrequency(SPI_FREQ);
 | 
			
		||||
    
 | 
			
		||||
        Ethernet.init(SS);
 | 
			
		||||
        delay(1000);
 | 
			
		||||
 | 
			
		||||
        if (Ethernet.begin(mac)) { // Dynamic IP setup
 | 
			
		||||
            Serial.println("DHCP OK!");
 | 
			
		||||
        }else{
 | 
			
		||||
            Serial.println("Failed to configure Ethernet using DHCP");
 | 
			
		||||
            // Check for Ethernet hardware present
 | 
			
		||||
            if (Ethernet.hardwareStatus() == EthernetNoHardware) {
 | 
			
		||||
            Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
 | 
			
		||||
            while (true) {
 | 
			
		||||
                delay(1); // do nothing, no point running without Ethernet hardware
 | 
			
		||||
            }
 | 
			
		||||
            }
 | 
			
		||||
            if (Ethernet.linkStatus() == LinkOFF) {
 | 
			
		||||
            Serial.println("Ethernet cable is not connected.");
 | 
			
		||||
            }
 | 
			
		||||
    
 | 
			
		||||
            Ethernet.begin(mac, ip, gateway, gateway, subnet);
 | 
			
		||||
            Serial.println("STATIC OK!");
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        Serial.print("Local IP : ");
 | 
			
		||||
        Serial.println(Ethernet.localIP());
 | 
			
		||||
        Serial.print("Subnet Mask : ");
 | 
			
		||||
        Serial.println(Ethernet.subnetMask());
 | 
			
		||||
        Serial.print("Gateway IP : ");
 | 
			
		||||
        Serial.println(Ethernet.gatewayIP());
 | 
			
		||||
        Serial.print("DNS Server : ");
 | 
			
		||||
        Serial.println(Ethernet.dnsServerIP());
 | 
			
		||||
 | 
			
		||||
        Serial.println("Ethernet Successfully Initialized"); 
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        Serial.println("Initialize as WiFi-AP");
 | 
			
		||||
        WiFi.softAP(ssid, pwd);
 | 
			
		||||
        WiFi.softAPConfig(ip, gateway, subnet);
 | 
			
		||||
    // WiFi.config(ip, gateway, subnet);
 | 
			
		||||
    // while (WiFi.status() != WL_CONNECTED) {
 | 
			
		||||
    //     Serial.print(".");
 | 
			
		||||
        Serial.print("WiFi AP enabled, IP = ");
 | 
			
		||||
        Serial.println(WiFi.localIP());
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    delay(500);
 | 
			
		||||
    //}
 | 
			
		||||
    // Serial.print("WiFi connected, IP = ");
 | 
			
		||||
    // Serial.println(WiFi.localIP());
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    // Initialize Art-Net
 | 
			
		||||
    Serial.println("Initialize Art-Net...");
 | 
			
		||||
    artnet.begin();
 | 
			
		||||
 | 
			
		||||
    // Initialize DMX ports
 | 
			
		||||
    Serial.println("Initialize DMX...");
 | 
			
		||||
    dmx.init();
 | 
			
		||||
 | 
			
		||||
    // if Artnet packet comes to this universe, this function is called
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue