mirror of
				https://github.com/esphome/esphome.git
				synced 2025-11-03 16:41:50 +00:00 
			
		
		
		
	Compare commits
	
		
			5 Commits
		
	
	
		
			wifi_ssid_
			...
			jesserockz
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					6c132be24c | ||
| 
						 | 
					08480d24f0 | ||
| 
						 | 
					41eb178f5a | ||
| 
						 | 
					d7b0060265 | ||
| 
						 | 
					e07f9a5b9c | 
@@ -7,7 +7,9 @@ from esphome.const import CONF_NAME, CONF_PORT
 | 
				
			|||||||
wled_ns = cg.esphome_ns.namespace("wled")
 | 
					wled_ns = cg.esphome_ns.namespace("wled")
 | 
				
			||||||
WLEDLightEffect = wled_ns.class_("WLEDLightEffect", AddressableLightEffect)
 | 
					WLEDLightEffect = wled_ns.class_("WLEDLightEffect", AddressableLightEffect)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CONFIG_SCHEMA = cv.All(cv.Schema({}), cv.only_with_arduino)
 | 
					AUTO_LOAD = ["socket"]
 | 
				
			||||||
 | 
					CONFIG_SCHEMA = cv.Schema({})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CONF_SYNC_GROUP_MASK = "sync_group_mask"
 | 
					CONF_SYNC_GROUP_MASK = "sync_group_mask"
 | 
				
			||||||
CONF_BLANK_ON_START = "blank_on_start"
 | 
					CONF_BLANK_ON_START = "blank_on_start"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,17 +1,7 @@
 | 
				
			|||||||
#ifdef USE_ARDUINO
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "wled_light_effect.h"
 | 
					#include "wled_light_effect.h"
 | 
				
			||||||
#include "esphome/core/log.h"
 | 
					
 | 
				
			||||||
#include "esphome/core/helpers.h"
 | 
					#include "esphome/core/helpers.h"
 | 
				
			||||||
 | 
					#include "esphome/core/log.h"
 | 
				
			||||||
#ifdef USE_ESP32
 | 
					 | 
				
			||||||
#include <WiFi.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef USE_ESP8266
 | 
					 | 
				
			||||||
#include <ESP8266WiFi.h>
 | 
					 | 
				
			||||||
#include <WiFiUdp.h>
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef USE_BK72XX
 | 
					#ifdef USE_BK72XX
 | 
				
			||||||
#include <WiFiUdp.h>
 | 
					#include <WiFiUdp.h>
 | 
				
			||||||
@@ -43,9 +33,9 @@ void WLEDLightEffect::start() {
 | 
				
			|||||||
void WLEDLightEffect::stop() {
 | 
					void WLEDLightEffect::stop() {
 | 
				
			||||||
  AddressableLightEffect::stop();
 | 
					  AddressableLightEffect::stop();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (udp_) {
 | 
					  if (this->socket_) {
 | 
				
			||||||
    udp_->stop();
 | 
					    this->socket_->close();
 | 
				
			||||||
    udp_.reset();
 | 
					    this->socket_.reset();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -58,27 +48,48 @@ void WLEDLightEffect::blank_all_leds_(light::AddressableLight &it) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void WLEDLightEffect::apply(light::AddressableLight &it, const Color ¤t_color) {
 | 
					void WLEDLightEffect::apply(light::AddressableLight &it, const Color ¤t_color) {
 | 
				
			||||||
  // Init UDP lazily
 | 
					  // Init UDP lazily
 | 
				
			||||||
  if (!udp_) {
 | 
					  if (this->socket_ == nullptr) {
 | 
				
			||||||
    udp_ = make_unique<WiFiUDP>();
 | 
					    this->socket_ = socket::socket_ip(SOCK_DGRAM, IPPROTO_IP);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!udp_->begin(port_)) {
 | 
					    int enable = 1;
 | 
				
			||||||
      ESP_LOGW(TAG, "Cannot bind WLEDLightEffect to %d.", port_);
 | 
					    int err = this->socket_->setsockopt(SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int));
 | 
				
			||||||
 | 
					    if (err != 0) {
 | 
				
			||||||
 | 
					      ESP_LOGW(TAG, "Socket unable to set reuseaddr: errno %d", err);
 | 
				
			||||||
 | 
					      // we can still continue
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    err = this->socket_->setblocking(false);
 | 
				
			||||||
 | 
					    if (err != 0) {
 | 
				
			||||||
 | 
					      ESP_LOGW(TAG, "Socket unable to set nonblocking mode: errno %d", err);
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct sockaddr_storage server;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    socklen_t sl = socket::set_sockaddr_any((struct sockaddr *) &server, sizeof(server), this->port_);
 | 
				
			||||||
 | 
					    if (sl == 0) {
 | 
				
			||||||
 | 
					      ESP_LOGW(TAG, "Socket unable to set sockaddr: errno %d", errno);
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    err = this->socket_->bind((struct sockaddr *) &server, sizeof(server));
 | 
				
			||||||
 | 
					    if (err != 0) {
 | 
				
			||||||
 | 
					      ESP_LOGW(TAG, "Socket unable to bind: errno %d", errno);
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::vector<uint8_t> payload;
 | 
					  std::vector<uint8_t> payload;
 | 
				
			||||||
  while (uint16_t packet_size = udp_->parsePacket()) {
 | 
					  uint8_t buf[1460];
 | 
				
			||||||
    payload.resize(packet_size);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!udp_->read(&payload[0], payload.size())) {
 | 
					  ssize_t len = this->socket_->read(buf, sizeof(buf));
 | 
				
			||||||
      continue;
 | 
					  if (len == -1) {
 | 
				
			||||||
    }
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  payload.resize(len);
 | 
				
			||||||
 | 
					  memmove(&payload[0], buf, len);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!this->parse_frame_(it, &payload[0], payload.size())) {
 | 
					  if (!this->parse_frame_(it, &payload[0], payload.size())) {
 | 
				
			||||||
      ESP_LOGD(TAG, "Frame: Invalid (size=%zu, first=0x%02X).", payload.size(), payload[0]);
 | 
					    ESP_LOGD(TAG, "Frame: Invalid (size=%zu, first=0x%02X).", payload.size(), payload[0]);
 | 
				
			||||||
      continue;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // FIXME: Use roll-over safe arithmetic
 | 
					  // FIXME: Use roll-over safe arithmetic
 | 
				
			||||||
@@ -283,5 +294,3 @@ bool WLEDLightEffect::parse_dnrgb_frame_(light::AddressableLight &it, const uint
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}  // namespace wled
 | 
					}  // namespace wled
 | 
				
			||||||
}  // namespace esphome
 | 
					}  // namespace esphome
 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif  // USE_ARDUINO
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,15 +1,12 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef USE_ARDUINO
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#include "esphome/core/component.h"
 | 
					 | 
				
			||||||
#include "esphome/components/light/addressable_light_effect.h"
 | 
					#include "esphome/components/light/addressable_light_effect.h"
 | 
				
			||||||
 | 
					#include "esphome/components/socket/socket.h"
 | 
				
			||||||
 | 
					#include "esphome/core/component.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class UDP;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace esphome {
 | 
					namespace esphome {
 | 
				
			||||||
namespace wled {
 | 
					namespace wled {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -34,7 +31,7 @@ class WLEDLightEffect : public light::AddressableLightEffect {
 | 
				
			|||||||
  bool parse_dnrgb_frame_(light::AddressableLight &it, const uint8_t *payload, uint16_t size);
 | 
					  bool parse_dnrgb_frame_(light::AddressableLight &it, const uint8_t *payload, uint16_t size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  uint16_t port_{0};
 | 
					  uint16_t port_{0};
 | 
				
			||||||
  std::unique_ptr<UDP> udp_;
 | 
					  std::unique_ptr<socket::Socket> socket_;
 | 
				
			||||||
  uint32_t blank_at_{0};
 | 
					  uint32_t blank_at_{0};
 | 
				
			||||||
  uint32_t dropped_{0};
 | 
					  uint32_t dropped_{0};
 | 
				
			||||||
  uint8_t sync_group_mask_{0};
 | 
					  uint8_t sync_group_mask_{0};
 | 
				
			||||||
@@ -43,5 +40,3 @@ class WLEDLightEffect : public light::AddressableLightEffect {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}  // namespace wled
 | 
					}  // namespace wled
 | 
				
			||||||
}  // namespace esphome
 | 
					}  // namespace esphome
 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif  // USE_ARDUINO
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user