Tan See Youu
Published © GPL3+

Crying AED

In cases of cardiac arrest, every moment counts. AED which able to cry (alarm) can easily gain attraction of people who looking for it.

IntermediateShowcase (no instructions)2,536

Things used in this project

Software apps and online services

AWS IoT
Amazon Web Services AWS IoT

Story

Read more

Schematics

schematic

basically just connect a speaker will do

Code

Crying AED LinkIt ONE source code

Arduino
LinkIT one source code for crying AED
#include <LBT.h>
#include <LBTClient.h>
#include <LAudio.h>


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#include <vmsock.h>
#include <net.h>
#include <mtk.h>
#include <signal.h>
#include <limits.h>
#include "aws_iot_mqtt_interface.h"
#include "aws_iot_version.h"
#include "aws_iot_log.h"
#include "aws_mtk_iot_config.h"
#ifdef connect
#undef connect
#endif
#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>

static LBTDeviceInfo info = {0};
boolean find = 0;
boolean exist = 0;
//#define SPP_SVR "SYRedmi" // it should be the prefer server's name,  customize it yourself.
#define ard_log Serial.printf
int read_size = 0;
char SPP_SVR[] = "";

/**
 * @brief Default MQTT HOST URL is pulled from the aws_iot_config.h
 */
char HostAddress[255] = AWS_IOT_MQTT_HOST;
/**
 * @brief Default MQTT port is pulled from the aws_iot_config.h
 */
VMINT port = AWS_IOT_MQTT_PORT;
/**
 * @brief This parameter will avoid infinite loop of publish and exit the program after certain number of publishes
 */
uint32_t publishCount = 0;

char cafileName[] = AWS_IOT_ROOT_CA_FILENAME;
char clientCRTName[] = AWS_IOT_CERTIFICATE_FILENAME;
char clientKeyName[] = AWS_IOT_PRIVATE_KEY_FILENAME;

LWiFiClient c;
bool infinitePublishFlag;
char cPayload[100];
int32_t i;
int rc;

int32_t MQTTcallbackHandler(MQTTCallbackParams params) {

  Serial.println("Subscribe callback");
  //receive the subscribed message, which is the bluetooth name sent from phone app
  SPP_SVR[] = params.MessageParams.pPayload;

//  INFO("%.*s\t%.*s",
//      (int)params.TopicNameLen, params.pTopicName,
//      (int)params.MessageParams.PayloadLen, (char*)params.MessageParams.pPayload);

  return 0;
}

void disconnectCallbackHandler(void) {
	Serial.println("MQTT Disconnect");
}

MQTTConnectParams connectParams;
MQTTSubscribeParams subParams;
MQTTMessageParams Msg;
MQTTPublishParams Params;

// invoked in main thread context
void bearer_callback(VMINT handle, VMINT event, VMUINT data_account_id, void *user_data)
{
    if (VM_BEARER_WOULDBLOCK == g_bearer_hdl)
    {
        g_bearer_hdl = handle;
    }
    
    switch (event)
    {
        case VM_BEARER_DEACTIVATED:
            break;
        case VM_BEARER_ACTIVATING:
            break;
        case VM_BEARER_ACTIVATED:
              /************************ Add your code here ************************/ 
            
              rc = NONE_ERROR;
              i = 0;
              infinitePublishFlag = true;
  
              connectParams = MQTTConnectParamsDefault;
  
              connectParams.KeepAliveInterval_sec = 10;
              connectParams.isCleansession = true;
              connectParams.MQTTVersion = MQTT_3_1_1;
              connectParams.pClientID = "CSDK-test-device";
              connectParams.pHostURL = HostAddress;
              connectParams.port = port;
              connectParams.isWillMsgPresent = false;
              connectParams.pRootCALocation = cafileName;
              connectParams.pDeviceCertLocation = clientCRTName;
              connectParams.pDevicePrivateKeyLocation = clientKeyName;
              connectParams.mqttCommandTimeout_ms = 2000;
	      connectParams.tlsHandshakeTimeout_ms = 5000;
	      connectParams.isSSLHostnameVerify = true;// ensure this is set to true for production
	      connectParams.disconnectHandler = disconnectCallbackHandler;
  
              rc = aws_iot_mqtt_connect(&connectParams);
              if (NONE_ERROR != rc) {
                  Serial.println("Error in connecting...");
              }
  
              subParams = MQTTSubscribeParamsDefault;
              subParams.mHandler = MQTTcallbackHandler;
              subParams.pTopic = AWS_IOT_TOPIC_NAME;
              subParams.qos = QOS_0;
              
              if (NONE_ERROR == rc) {
                  Serial.print("Subscribing...");
                  rc = aws_iot_mqtt_subscribe(&subParams);
                  if (NONE_ERROR != rc) {
                      Serial.println("failed in iot_mqtt_subscribe.");
                  }
              }
              
              /************************ End for your own code ************************/ 
              break;
        case VM_BEARER_DEACTIVATING:
            break;
        default:
            break;
    }
}

boolean bearer_open(void* ctx){
    g_bearer_hdl = vm_bearer_open(VM_BEARER_DATA_ACCOUNT_TYPE_WLAN,  NULL, bearer_callback);
    return true;
}

void setup()  
{
  Serial.begin(9600);
  
  // begin BT
  bool success = LBTClient.begin();
  if( !success )
  {
      ard_log("Cannot begin Bluetooth Client successfully\n");
      delay(0xffffffff);
  }
  else
  {
      ard_log("Bluetooth Client begin successfully\n");
      
      
  }
  LWiFi.begin();
  Serial.begin(9600);
  while(!Serial)
    delay(100);

  // keep retrying until connected to AP
  Serial.print("  . Connecting to AP...");
  while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }
  Serial.println("ok");

  CONNECT_IP_ADDRESS = IP_ADDRESS;
  CONNECT_PORT = port;
  
  LTask.remoteCall(bearer_open, NULL);
}
 
void loop()
{
      // scan the devices around
      int num = LBTClient.scan(2);
      ard_log("scanned device number [%d]", num);
      for (int i = 0; i < num; i++)
      {
        memset(&info, 0, sizeof(info));
        // to check the prefer master(server)'s name
        if (!LBTClient.getDeviceInfo(i, &info))
        {
            continue;
        }
        ard_log("getDeviceInfo [%02x:%02x:%02x:%02x:%02x:%02x][%s]", 
            info.address.nap[1], info.address.nap[0], info.address.uap, info.address.lap[2], info.address.lap[1], info.address.lap[0],
            info.name);
       
        if (0 == strcmp(info.name, SPP_SVR))
        {
            find = 1;
            ard_log("found\n");
            LAudio.playFile( storageFlash,(char*)"people021.wav");
            LAudio.setVolume(3);
            delay(2000);
            break;
        }else{
          LAudio.stop();
        }
      }

    ard_log("loop client\n");

}

Credits

Tan See Youu

Tan See Youu

5 projects • 67 followers
someone who love programming and create new stuff

Comments