블루이노/BLE

bluinno BLE chatting android app

ZEROWIN.TECH 2020. 12. 2. 12:07
728x90

블루이노 소스코드

///////////////////////////////////////////////
//
// 블루이노2 & 앱인벤터2와 채팅
// 
// ZEROWIN CODING
// 2017.12.13
/////////////////////////////////////////////// 
 
 #include <RFduinoBLE.h>  
 
 #include <SoftwareSerial.h>
 
void setup() {
  
    // put your setup code here, to run once:
    Serial.begin(9600);
    
 
    RFduinoBLE.advertisementData = "chat";
 
    // start the BLE stack
    RFduinoBLE.begin();      
 
    Serial.println("BLUEINNO2 CHATTING START!!!");
 
}
 
  boolean ble_bConnected = false;
void RFduinoBLE_onConnect(void) {
  Serial.println("RFduinoBLE_onConnect...");
 
  ble_bConnected = true;
}
 
void RFduinoBLE_onDisconnect(void) {
  Serial.println("RFduinoBLE_onDisconnect...");
 
  ble_bConnected = false;
}
 
void RFduinoBLE_onReceive(char *data, int len) {
  char temp[128] = { 0x00, };
 
  strcpy(temp, "RECV:\t");
  strncpy(temp+5, data, len);
  Serial.println(temp);
}
 
char ch;
 
char sendText[128] = { 0x00, };
int sendCount = 0;
 
int recvTimeout = 0;
 
void loop() {
  // put your main code here, to run repeatedly:
 
  if(Serial.available()) 
  {
    Serial.print("SEND:\t");
 
    int pos = 0;
    memset(sendText, 0x00, 128);
    
    sendCount += 1;
    sprintf(sendText, "%04d: ", sendCount);
    pos += 6;
    
    while (Serial.available()) 
    {
      ch = Serial.read();
      sendText[pos] = ch; pos += 1;
      Serial.write(ch);
    }
 
    // TODO:
    RFduinoBLE.send(sendText, pos);
 
    memset(sendText, 0x00, 128);
    pos = 0;
    
    Serial.println();
    
  }
 
  delay(1000);
}

 

 

'블루이노 > BLE' 카테고리의 다른 글

Blueinno 앱 업그레이드  (0) 2020.10.31