AP mode

Dependencies:   NetworkSocketAPI WizFi310Interface mbed

Fork of WizFi310_TCP_Echo_Server_Example by WIZnet

push.cpp

Committer:
maru536
Date:
2017-10-02
Revision:
2:8d119e9b8f5a

File content as of revision 2:8d119e9b8f5a:

#include "push.h"
#include "TCPSocket.h"

bool requestNoti(TCPSocket *socket, char* id, char* buf)
{
    char body[200] = "";
    int len;
  int pos = 0;
  int bracketCount = 0;
  int isEndContent = false;
  int isStartContent = false;
    printf("\n11\n");
  if (socket->connectSSL("fcm.googleapis.com", 443) == 0) {
    printf("\n12\n");
    strcpy(body, "{\"to\": \"");
    strcat(body, id);
    strcat(body, "\"}\n\n");
    len = strlen(body);
    
    sprintf(buf, "POST /fcm/send HTTP/1.1\nHost: fcm.googleapis.com\nContent-Type: application/json\nAuthorization: key=AAAA5sg2OQw:APA91bE_cHSew6Je4CcAcFbGq__QmpsXt_jyYMoUQt9vhgMDarqWlE2wopdp3TCSz_FD9mvg_Kjvf_82zcEn9hJ20mNx-FVlNAgc9NND29U9DNGSyBJmmeqfA5gDw-dkpKy2Vt10b_xd\nContent-Length: %d\n\n%s", len, body);
    
    socket->send(buf, MAX_BUF_SIZE);
    socket->recv(buf, MAX_BUF_SIZE);
    
    printf("Request to FCM server\n");
    return true;
  }
  else {
    printf("FCM Connect Fail\n");
    return false;
  }
}