본문 바로가기

ioT

wemos d1 mini를 이용한 485 serial monitor

요즘 아파트에는 월패드가 설치되어 있다.

이런 기기들은 ha나 st hub에 연결되지 않기 때문에 이것을 활용해 다른 기기들과 스마트홈을 만드려면

여러 경로를 거쳐 제어가능하도록 만들어야 한다.

 

이미 적지 않은 방식이 알려져 있고, 이와 관련되어 제품을 만들고 사업을 진행하는 업체도 있는듯 하다.

 

관련 정보는 

 

https://cafe.naver.com/koreassistant?iframe_url=/MyCafeIntro.nhn%3Fclubid=29860180

 

HomeAssistant : 네이버 카페

스마트홈을 이용중이고 앞으로 이용할 사람들의 모임. 셀프인테리어, 스마트홈 인테리어, IOT DIY.

cafe.naver.com

cafe.naver.com/stsmarthome

 

Smartthings & IoT ho... : 네이버 카페

스마트싱스와 같은 IOT허브를 이용하여 홈네트워크 및 스마트홈을 구축

cafe.naver.com

 

여기서 월패드 rs485 등으로 검색하면 다양한 방식과 솔루션등이 이미 적용되어 활용하는 모습을 볼 수있다.

 

 

 

 

나의 경우 이미 esphome을 이용해  월패드, 전열교환기 등에 설치하여

 

조명, 보일러, 콘센트, 일괄스위치, 전열교환기를 자동화 하여 활용하는 중이다.

 

rubato-blog.tistory.com/entry/ESPHome%EC%9C%BC%EB%A1%9C-%EC%A0%84%EC%97%B4%EA%B5%90%ED%99%98%EA%B8%B0-%EC%BB%A8%ED%8A%B8%EB%A1%A4%EB%9F%AC-%EC%A0%9C%EC%96%B4%ED%95%98%EA%B8%B0

 

ESPHome으로 전열교환기 컨트롤러 제어하기

새집으로 이사하고 ​ '누워서 조명끄기'라는 단순한 욕망은 ​ 집밖에 나가기 힘든 요즘의 상황과 맞물려 ​ 고생스런 취미가 되었다. ​ ​ ​ ​ 원래 달려있으나 불편하기 그지없던 월패드

rubato-blog.tistory.com

 

m.cafe.naver.com/ca-fe/web/cafes/stsmarthome/articles/12973?useCafeId=false

 

월패드 연동 ESPHOME RS485 컴포넌트 공유

2020-04-01 업데이트1. 체크섬 2byte 대응 checksum2 옵션 추가 (add sum)2. state_response, sub_device, state_on, ...

cafe.naver.com

 

어떤 방식으로 월패드에 접근 하든 가장 먼저 해야할 일은 월패드에서 주고 받는 통신신호, 패킷을 모니터링하는 것이다.

 

그러니 패킷을 모니터링하는 방법을 정하는게 가장 먼저할일이다.

 

가능한 방식으로 

 

 

USB to RS485

Elfin-EW11

이런 제품들을 활용할 수 있다.

 

나의 경우도 800~1000원 정도하는 usb-rs485 모듈을

 

활용하여 싱크대 밑에 라즈베리파이를 설치하여 활용하였다.

 

 

이런 경우 싱크대 하단으로 랜선을 끌어오지 않으면

 

라즈베리파이를 무선으로 운용하여야하는 점을 고려해야만하고

 

nas를 이용하는 사용자의 경우 여러 어려움이 생긴다.

 

 

그래서 무선으로 패킷을 모니터링 할수 있는 ew11 이 필요하게 된다.

 

많은 사용자들도 주로 ew11을 활용하는 듯하다.

 

 

 

이미 esp32와 으로 꾸민 회로를 통해  월패드를 제어하는 나의 입장에서  ew11은 필수는 아니어서

 

조금더 저렴한 무선 패킷 모니터링 방식을 소개한다.

 

 

준비물은 2가지.

 

ko.aliexpress.com/item/4001198977683.html?spm=a2g0o.productlist.0.0.60a5c120fSpq1u&algo_pvid=cbd9e328-1751-45c6-8ad6-c1fe43e35d5f&algo_expid=cbd9e328-1751-45c6-8ad6-c1fe43e35d5f-3&btsid=0bb0623c16174298455745576e7194&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

 

1.1US $ 27% OFF|S485 to TTL 모듈 TTL to RS485 신호 변환기 3V 5.5V 절연 단일 칩 직렬 포트 UART 산업용 등급

Smarter Shopping, Better Living! Aliexpress.com

ko.aliexpress.com

 

ko.aliexpress.com/item/32831353752.html?spm=a2g0o.productlist.0.0.6b8c71c6QL6cbc&algo_pvid=null&algo_expid=null&btsid=0bb0623c16174299468025854e7194&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

 

1.78US $ 10% OFF|WeMos D1 Mini Pro V3.0 NodeMcu 4MB/16MB 바이트 루아 와이파이 사물 개발 보드 기반 ESP8266 CH340

Smarter Shopping, Better Living! Aliexpress.com

ko.aliexpress.com

 

 

그리고 다음의 사이트를 활용하여 코딩하고 컴파일하였다.

 

www.roboremo.com/projects/esp/esp8266-tcp-to-serial

 

ESP8266 TCP to Serial

This page explains how to program the ESP-01 module to become a WiFi to Serial Transparent Bridge.

www.roboremo.com

 

 

 

 

하드웨어의 구성은 다음을 참고하면 된다.

 

cafe.naver.com/stsmarthome/10095

 

RS485 소켓통신(ESPEasy) ser2net 이용(코콤)

RS485 to UART, Wemos D1 mini를 이용하여소켓 통신하는 방법 공유해 드립니다.카페 여러 회원님들께서 협소한 장소, 라즈베리 RS485 수신기 전용 사용, ...

cafe.naver.com

 

 

 

나의 경우는 아두이노 IDE를 통해 아래 코드에서 39~41에 공유기 정보를 수정하여 컴파일하고 업로드하였다.

 

// ESP8266 WiFi <-> UART Bridge
// by RoboRemo
// www.roboremo.com

// Disclaimer: Don't use RoboRemo for life support systems
// or any other situations where system failure may affect
// user or environmental safety.

#include <ESP8266WiFi.h>


// config: ////////////////////////////////////////////////////////////

#define UART_BAUD 9600
#define packTimeout 5 // ms (if nothing more on UART, then send packet)
#define bufferSize 8192

//#define MODE_AP // phone connects directly to ESP
#define MODE_STA // ESP connects to WiFi router

#define PROTOCOL_TCP
//#define PROTOCOL_UDP


#ifdef MODE_AP
// For AP mode:
const char *ssid = "mywifi";  // You will connect your phone to this Access Point
const char *pw = "qwerty123"; // and this is the password
IPAddress ip(192, 168, 0, 1); // From RoboRemo app, connect to this IP
IPAddress netmask(255, 255, 255, 0);
const int port = 9876; // and this port
// You must connect the phone to this AP, then:
// menu -> connect -> Internet(TCP) -> 192.168.0.1:9876
#endif


#ifdef MODE_STA
// For STATION mode:
const char *ssid = "myrouter";  // Your ROUTER SSID
const char *pw = "password"; // and WiFi PASSWORD
const int port = 9876;
// You must connect the phone to the same router,
// Then somehow find the IP that the ESP got from router, then:
// menu -> connect -> Internet(TCP) -> [ESP_IP]:9876
#endif

//////////////////////////////////////////////////////////////////////////




#ifdef PROTOCOL_TCP
#include <WiFiClient.h>
WiFiServer server(port);
WiFiClient client;
#endif

#ifdef PROTOCOL_UDP
#include <WiFiUdp.h>
WiFiUDP udp;
IPAddress remoteIp;
#endif


uint8_t buf1[bufferSize];
uint16_t i1=0;

uint8_t buf2[bufferSize];
uint16_t i2=0;



void setup() {

  delay(500);
  
  Serial.begin(UART_BAUD);

  #ifdef MODE_AP 
  //AP mode (phone connects directly to ESP) (no router)
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(ip, ip, netmask); // configure ip address for softAP 
  WiFi.softAP(ssid, pw); // configure ssid and password for softAP
  #endif

  
  #ifdef MODE_STA
  // STATION mode (ESP connects to router and gets an IP)
  // Assuming phone is also connected to that router
  // from RoboRemo you must connect to the IP of the ESP
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pw);
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
  }
  #endif

  #ifdef PROTOCOL_TCP
  Serial.println("Starting TCP Server");
  server.begin(); // start TCP server 
  #endif

  #ifdef PROTOCOL_UDP
  Serial.println("Starting UDP Server");
  udp.begin(port); // start UDP server 
  #endif
}


void loop() {

  #ifdef PROTOCOL_TCP
  if(!client.connected()) { // if client not connected
    client = server.available(); // wait for it to connect
    return;
  }

  // here we have a connected client

  if(client.available()) {
    while(client.available()) {
      buf1[i1] = (uint8_t)client.read(); // read char from client (RoboRemo app)
      if(i1<bufferSize-1) i1++;
    }
    // now send to UART:
    Serial.write(buf1, i1);
    i1 = 0;
  }

  if(Serial.available()) {

    // read the data until pause:
    
    while(1) {
      if(Serial.available()) {
        buf2[i2] = (char)Serial.read(); // read char from UART
        if(i2<bufferSize-1) i2++;
      } else {
        //delayMicroseconds(packTimeoutMicros);
        delay(packTimeout);
        if(!Serial.available()) {
          break;
        }
      }
    }
    
    // now send to WiFi:
    client.write((char*)buf2, i2);
    i2 = 0;
  }
  #endif



  #ifdef PROTOCOL_UDP
  // if there’s data available, read a packet
  int packetSize = udp.parsePacket();
  if(packetSize>0) {
    remoteIp = udp.remoteIP(); // store the ip of the remote device
    udp.read(buf1, bufferSize);
    // now send to UART:
    Serial.write(buf1, packetSize);
  }

  if(Serial.available()) {

    // read the data until pause:
    //Serial.println("sa");
    
    while(1) {
      if(Serial.available()) {
        buf2[i2] = (char)Serial.read(); // read char from UART
        if(i2<bufferSize-1) {
          i2++;
        }
      } else {
        //delayMicroseconds(packTimeoutMicros);
        //Serial.println("dl");
        delay(packTimeout);
        if(!Serial.available()) {
          //Serial.println("bk");
          break;
        }
      }
    }

    // now send to WiFi:  
    udp.beginPacket(remoteIp, port); // remote IP and port
    udp.write(buf2, i2);
    udp.endPacket();
    i2 = 0;
  }
    
  #endif
  
  
}

 

 

그럴듯하게 케이싱까지...

 

 

 

 

 

 

싱크대 밑 보일러 컨트롤러에 잘 설치하고

 

serialportmon으로 접속하여 공유기에서 할당된 ip를 확인하고 설정한 포트번호를 입력한다.

 

 

 

패킷도 이상없이 잘 올라오는 것을 확인.

 

 

 

장점 . 3000원 이하의 저렴한 가격

 

단점. 내구성 검증 안됨. (아마, 괜찮을 듯.....)

     케이싱 없으면 조금 불편하나 꼭꼭 숨기면 또 상관없음.