본문 바로가기
코딩/아두이노

아두이노로 스마트폰에 Pushbullet을 이용하여 알림 보내기

by DIYver 2021. 3. 25.

 

 

 

 

<목표>

 

 

- 아두이노 IoT 프로젝트를 하다보면, 스마트폰에 알림을 보내야 하는 경우가 참 많다.

하지만 어떻게 해야할지 막막하기만 한데, 

어플을 만들어야 하는건 아닌지... 블루투스로 해서 해결해야 하는 것인지...

오늘 이 포스팅에서 정말 간단하고 쉽게 아두이노로 스마트폰에 알림을 보내는 방법을 소개해보자 한다.

 


<준비물>

 

 

- NodeMCU 또는 wifi모듈 ESP8266과 아두이노(우노, 나노, 메가)


<회로도>

 

회로 없음

 


우선 Pushbullet 과 PushingBox 사이트를 이용해야한다.

둘 다 무료이고, 인터넷만 연결되는 상황이면 사용가능하다.

그리고 구글 계정으로 로그인이 가능하므로 간편하다.

 

 

www.pushbullet.com/

 

Pushbullet - Your devices working better together

Chat with friends Pushbullet works great on all of your devices, which makes sharing and chatting with friends more convenient than ever.

www.pushbullet.com

www.pushingbox.com/

 

PushingBox - Notifications for your Internet of Things devices

Simple API PushingBox has only one API that you can trigger by HTTP request (GET/POST) or Email. You can call PushingBox from almost anything: Arduino Spark Core IFTTT Email SmartThings HTTP Request Your own script Vera, Fibaro, ... Dozen of services We co

www.pushingbox.com

두 사이트에 접속해서 로그인하고

Pushbullet 부터 설정을 해주어야 한다.

 

Devices 를 누르면 처음에 디바이스가 없는 상태일 것이다.

필자는 등록을 했기에 목록에 장치가 하나 잡혀있는 상태이다.

 

이제 스마트폰에서 똑같이 Pushbullet 어플을 설치해야 한다.

play.google.com/store/apps/details?id=com.pushbullet.android&referrer=utm_source%3Dpushbullet.com

 

Pushbullet - SMS on PC and more - Google Play 앱

Pushbullet is "the app you never knew you needed", according to CNET. Here's why: Stay Connected • Conveniently send and receive SMS messages from your computer • Reply to messages from many popular apps including WhatsApp, Kik, and Facebook Messenger

play.google.com

 

똑같이 스마트폰에서 구글계정으로 로그인하고 다시 컴퓨터에서 Pushbullet을 확인하면 장치가 등록된 것을 확인할 수 있다.

 

 

이제 내 스마트폰에 알림을 보내보자.

방법은 간단하다.

그냥 디바이스에서 자신의 핸드폰을 선택하고

채팅을 치면 된다.

 

잠금화면에서도 알림이 잘 뜨는 것을 확인할 수 있고,

상태바를 내려서도 알림이 잘 온 것을 확인할 수 있다.

 

물론 알림이 올 때, 소리도 같이 울린다.

 

 

 

이제 Pushbullet 세팅은 끝났다.

 

아두이노에서 알림을 주기 위해서는 

PushingBox 를 이용해야 한다.

 

똑같이 PushingBox 에서 구글계정으로 로그인을 한다.

 

그리고 우선 서비스를 하나 만들어야 한다.

 

 

서비스 항목 중에서 Pushbullet을 선택한다.

 

 

Pushbullet을 선택하고

몇가지 항목을 입력해야 한다.

 

첫번째 항목은 마음대로 입력하면 된다.

프로젝트 이름을 입력하면 되겠다.

 

두번째 항목이 제일 중요한데 Access token을 알아야 한다.

이 항목은 Pushbullet 에서 발급을 받으면 된다.

Pushbullet 화면에서 setting에 들어가면 떡하니 Create Access Token 이라는 버튼이 존재한다.

그 버튼을 누르고 토큰을 복사해서 위의 입력창에 붙여넣기 하면 된다.

 

 

 

그다음에 My Scenarios 에서 시나리오를 등록해야 한다.

 

위와같이 임의로 항목이름을 넣고 Add 를 누르자.

 

그리고 Add an Action 버튼을 누르자.

 

자신의 Pushbullet 이름을 확인하고 Add an action with this service 버튼을 누르자.

 

 

알림 내용을 위의 창에서 설정을 해줄 수 있다.

알림창 제목과 알림 메세지 내용을 입력해주면 된다.

사진을 보내고 싶은 경우 URL로 해서 입력해주면 되는 듯 하다.

 

 

 

시나리오를 등록했으면 이제 Test 를 해보자.

스마트폰에 알림이 잘 뜨면 성공인 것이다.

 

 

이제는 아두이노에서 세팅만 해주면 된다.

 

 

아두이노에서 필요한 항목은 PushingBox 의 Device ID 가 필요하다.

 

조그맣게 나와있으므로 찾기 힘들 수도 있다.

 

 

 

 

아두이노 코드에서 핵심 내용만 설명해보자면

    client.print(F("GET /pushingbox?devid="));
    client.print(DEVICEID);
    client.print(F(" HTTP/1.1\r\n"));
    client.print(F("Host: api.pushingbox.com\r\n"));
    client.print(F("User-Agent: Arduino\r\n"));
    client.print(F("\r\n\r\n"));

위의 코드가 PushingBox 사이트로 신호를 보내는 코드이다.

 

자신의 Device ID 를 입력하면 된다.

 

그러면 Device ID로 신호가 들어오면 PushingBox 에서 Pushbullet 으로 신호를 다시 보내게 되며,

Pushbullet에서 스마트폰으로 또 신호를 보내게 된다.

 

코드로 해서 테스트를 해보자.

 

 

 

 

 

 

<코드>

 

 

#include <ESP8266WiFi.h>

#ifndef STASSID
#define STASSID ""
#define STAPSK  ""
#endif

#define DEVICEID  ""

const char* ssid     = STASSID;
const char* password = STAPSK;

int status = WL_IDLE_STATUS;       // the Wifi radio's status

char server[] = "api.pushingbox.com";

unsigned long lastConnectionTime = 0;         // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 5000L; // delay between updates, in milliseconds

boolean getIsConnected = false;

String rcvbuf;

// Initialize the 

WiFiClient client;

void httpRequest();
void printWifiStatus();

void setup() {
  Serial.begin(115200);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  /* Explicitly set the ESP8266 to be a WiFi-client, otherwise, it by default,
     would try to act as both a client and an access-point and could cause
     network-issues with your other WiFi-devices on your WiFi-network. */
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);




  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}




void loop() {

while (client.available()) {
    char c = client.read();
    if ( c != NULL ) {
      if (rcvbuf.length() > 20)
        rcvbuf = "";
      rcvbuf += c;
      Serial.write(c);
    }
  }
  // if 5 seconds have passed since your last connection,
  // then connect again and send data
  if (millis() - lastConnectionTime > postingInterval) {
    
      httpRequest();
    
  }
  rcvbuf = "";

}


// this method makes a HTTP connection to the server
void httpRequest() {
  Serial.println();

  // close any connection before send a new request
  // this will free the socket on the WiFi shield
  client.stop();

  // if there's a successful connection
  if (client.connect(server, 80)) {
    Serial.println("Connecting...");

    // send the HTTP PUT request
    client.print(F("GET /pushingbox?devid="));
    client.print(DEVICEID);
    client.print(F(" HTTP/1.1\r\n"));
    client.print(F("Host: api.pushingbox.com\r\n"));
    client.print(F("User-Agent: Arduino\r\n"));
    client.print(F("\r\n\r\n"));

    // note the time that the connection was made
    lastConnectionTime = millis();
    getIsConnected = true;
  }
  else {
    // if you couldn't make a connection
    Serial.println("Connection failed");
    getIsConnected = false;
  }
}

 


<실행 결과>

 

 

알림이 정상적으로 도착하는 것을 확인할 수 있다.

5초마다 신호를 보내게 설정했어서 스팸마냥 올것이다.

테스트만 하고 아두이노 전원을 차단하는 것이 좋다.

 

왜냐하면 PushingBox는 일일 메세지 개수 한도가 있기 때문이다.

 

100건을 넘으면 더 못 쓰기 때문에 필요할 때에만 쓸 수 있도록 하자.

 

 

 

 


※ 궁금하시거나 질문사항이 있으시면 댓글로 작성해주시면 답변해 드릴 수 있는 부분에서 친절히 답변드리겠습니다!

 

 

 

 

댓글