메뉴 건너뛰기

정보자료게시판

장비/디자인/구조

지그비(XBee)-ESP32-Blynk 오토메이션 종합 01

by 라키 posted Sep 21, 2018
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

지그비(XBee)-ESP32-Blynk 오토메이션 종합 01

목표

센서 지그비[건전지-LED-지그비] 2대가 코디네이터[지그비-ESP32]에게 지그비 통신을 통해 센서 정보를 보내고 그 정보는 블링크를 통해 핸드폰으로 전송.

핸드폰에서 센서 정보를 보고 코디네이터에 연결된 릴레이에게 온-오프 명령을 내리거나, 핸드폰에서 설정한 시간(시간 단위 반복)이 되면 해당 릴레이가 온-오프 된다.

테스트 소스

#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

#include <time.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

int timezone=9;
int starttime=45;
int endtime=55;

float value01;
byte sig[30];
int Relay01=25;
int Relay02=32;
int Relay03=33;

int relayno=0;

int relayon=0;
int relaystate[3]={0,0,0};

BlynkTimer timer;

// This function sends Arduino&#39;s up time every second to Virtual Pin (5).
// In the app, Widget&#39;s reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.

void myTimerSensor()
{
//  0x8B : Sensor02 , 0x27 : Sensor03
//  = Relay02 , Relay03
//  = relaystate[1] , relaystate[2]
//  = VP6 : VP7
//  = VP0 : VP1
//  Sensor01 = VP5

  if(Serial.available() > 21) {
    while (Serial.read() != 0x7E);

    for(int i=0; i<21; i++){
      sig[i]=Serial.read();
      if(sig[i]==0x7E) break;
    }

    int analogReading=sig[18] + sig[19];
    value01=analogReading;

    if (value01<50) relayon=1;
    else if(value01>50) relayon=0;

    if(sig[10] == 0x8B) relaystate[1]=relayon;
    else if(sig[10] == 0x27) relaystate[2]=relayon;
  }
}

BLYNK_WRITE(V0)      // Slide V0 widget -> arduino
{
  int pinData = param.asInt();
  starttime=pinData;
}

BLYNK_WRITE(V1)      // Slide V1 widget -> arduino
{
  int pinData = param.asInt();
  endtime=pinData;
}

BLYNK_WRITE(V2)      // Button widget -> arduino
{
  int pinData = param.asInt();
  if(pinData == 1)    digitalWrite(Relay02,HIGH);  
  else              digitalWrite(Relay02, LOW);
}

BLYNK_WRITE(V3)      // Button widget -> arduino
{
  int pinData = param.asInt();
  if(pinData == 1)      digitalWrite(Relay03,HIGH);
  else              digitalWrite(Relay03, LOW);
}

void alarm()
{
  Blynk.virtualWrite(V6, relaystate[1]);  
  Blynk.virtualWrite(V7, relaystate[2]);  
}

void TimePrint() {
  String a[3];

  time_t now = time(nullptr);
  struct tm * timeinfo;
  timeinfo = localtime(&now); 
  a[0]=String(timeinfo->tm_sec, DEC); 
  a[1]=String(timeinfo->tm_min, DEC); 
  a[2]=String((timeinfo->tm_hour), DEC);  
  if(timeinfo->tm_sec<10)      a[0]="0"+a[0];
  if(timeinfo->tm_min<10)      a[1]="0"+a[1];
  if(timeinfo->tm_hour<10)     a[2]="0"+a[2];

  char tempstr[3];
  a[1].substring(0, 2).toCharArray(tempstr, 3);
  int minute = atoi(tempstr);

  if(minute >= starttime && minute <= endtime) {
    relaystate[0]=HIGH;
  }
  else {
    relaystate[0]=LOW;
  }
  digitalWrite(Relay01,relaystate[0]);
  Blynk.virtualWrite(V5, relaystate[0]);
}

void serialFlush(){
  while(Serial.available() > 0) {
    char t = Serial.read();
//    if (t==0x7E) break;
  }
} 

void setup()
{
  // Debug console
  Serial.begin(9600);

  pinMode(Relay01,OUTPUT);
  pinMode(Relay02,OUTPUT);
  pinMode(Relay03,OUTPUT);

  Blynk.begin(auth, ssid, pass);

  configTime(timezone * 3600, 0, "pool.ntp.org", "time.nist.gov");
  Serial.println("\nWaiting for time");
  while (!time(nullptr)) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("Time Setup");

  timer.setInterval(300L, myTimerSensor);
  timer.setInterval(1000L, TimePrint);
  timer.setInterval(1000L, alarm);
  timer.setInterval(2110L, serialFlush);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}

센서 지그비 회로 구성

  • 1.2V 건전지 3개로 3.6V 출력을 만듦(Ni-Mh 충전 건전지 2개 2.4V로는 센서가 정상 감지 못함)
  • D3번-LED-저항(220옴)을 연결
  • 각 3.6V 전원을 연결해줌

센서 지그비 설정(AT로 설정)

  • XCTU 다운로드(https://www.digi.com/resources/documentation/digidocs/90001526/tasks/t_download_and_install_xctu.htm)
  • 맥용 XCTU 프로그램도 있음
  • 셋팅으로 들어가면 XBEE S2C, 작성일 기준으로, Product Family는 XB24C로, Function set 은 ZIGBEE TH Reg, Firmware Version은 4060임
  • Help에서 Update Check, Update, Install 다 해주는 걸 권장하는데 시간이 좀 걸림
  • ID(PAN ID) 는 아무 숫자나 해도 되는데 수신부 지그비와 일치시켜야. 여기서는 1234로
  • JV(Channel Verification)은 enable(통상 채널 확인 하고 시작함)로,
  • CE(Coordinator Enable)은 disable로(Router 설정임),
  • AP(API enable)은 Transparent mode로(단순 통신 모드임)로 각 설정함
  • IR(IO Sampling Rate)는 하나는 1000(3E8), 다른 하나는 990(16진수 입력값으로는 3DE)으로 입력(완전 동일한 경우 각 센서들이 보내는 정보가 시간적으로 중복된 채로 반복되어 센서 정보를 번갈아 받기 어려운 문제가 있어서 시차를 줌)

코디네이터 지그비 회로 구성

  • ESP32의 RX,TX를 지그비의 TX,RX에 연결
  • 프로그램 업로드할때는 RX,TX 연결 선을 빼주어야 정상 업로드가 됨

수신부 지그비 설정(Coordinate API로 설정)

  • ID(PAN ID)는 위에서 적은 1234로
  • JV(Channel Verification)은 enable로,
  • CE(Coordinator Enable)은 enable(수신부 지그비는 Coordinator임)로,
  • AP(API enable)은 API enable로 각 설정

향후 체크할 점

  • 어느 정도 목표치에 접근함
  • 건전지 3개로 전원을 공급받는 센서 지그비가 어느 정도 버텨줄지가 관건

참고한 영상

TAG •

  1. notice by Summa 2025/07/22 by Summa

    각종 사진들

  2. No Image notice by Summa 2025/04/02 by Summa

    꾸준히 하는 취미를 가져보기로 한다

  3. No Image 11Aug
    by Summa
    2025/08/11 by Summa

    클라우드 플레어 방화벽 설정

  4. 홈페이지 속도 지연 feat. 클라우드플레어

  5. No Image 27May
    by Summa
    2025/05/27 by Summa

    메일 서버 시놀로지 메일플러스의 구조

  6. No Image 23May
    by Summa
    2025/05/23 by Summa
    Replies 2

    라이믹스 홈페이지들 상태 이상

  7. No Image 20May
    by Summa
    2025/05/20 by Summa

    SSL 서비스에 있어 클라우드 플레어의 놀라운 점

  8. No Image 17May
    by Summa
    2025/05/17 by Summa

    전기요금 아끼는 방법 - 전기요금 절약 프로젝트

  9. No Image 16May
    by Summa
    2025/05/16 by Summa

    구글 제미나이 오류

  10. No Image 15May
    by Summa
    2025/05/15 by Summa
    Replies 1

    KT 인터넷 전화기 IP375 초기화하기

  11. 냉장고 교체 전력소비량 feat. 오래된 냉장고

  12. No Image 15Apr
    by Summa
    2025/04/15 by Summa

    삼성 냉장고 와이파이 연결 안됨 feat. 스마트싱스

  13. 01Apr
    by Summa
    2025/04/01 by Summa

    홈팟미니 이상 해결

  14. No Image 31Mar
    by Summa
    2025/03/31 by Summa

    맥 Numbers 넘버스에서 홈택스 txt 파일 올리기

  15. No Image 26Mar
    by Summa
    2025/03/26 by Summa

    아이폰 듀얼심 문자 안될때 해결 방법

  16. 시놀로지 클라우드플레어 DDNS 설정

  17. 집밥 그리고 밥솥

  18. 단렌즈를 포기하게 된 결정적 이유

  19. 공부폰 / 공신폰 만드는 방법

  20. No Image 03Feb
    by Summa
    2025/02/03 by Summa

    2번 서버 다운

  21. 워드프레스 멀티사이트 만들기

  22. 올해 산것 중 제일 잘 산것 - 전기자전거

Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 47 Next
/ 47
위로