Great progress ![]()
Yes, the message from the phone is in ble.buffer.
Using strcmp() is a way to test what is in the buffer.
if ((strcmp(ble.buffer, "test") == 0))
{Serial.println("Yay it works");}
Here is a sketch I wrote some time ago to manage an led blink with the SPI BLE friend so you'll have to change to the software serial object.
//#include <Arduino.h>
#include <SPI.h>
#include "Adafruit_BLE.h"
#include "Adafruit_BluefruitLE_SPI.h"
//#include "Adafruit_BluefruitLE_UART.h"
#include "BluefruitConfig.h"
/* ...hardware SPI, using SCK/MOSI/MISO hardware SPI pins and then user selected CS/IRQ/RST */
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
#define LED_PIN 13
unsigned long BLINKTIME = 1000;
unsigned long t_blink = 0L;
int blinkState = LOW;
void setup(void)
{
pinMode(LED_PIN, OUTPUT);
ble.begin();
ble.factoryReset();
Serial.begin(115200);
}
void loop(void)
{
// static int val = 0;
// Now Check for incoming characters from Bluefruit
ble.println("AT+BLEUARTRX");
ble.readline();
if ((strcmp(ble.buffer, "STATUS") == 0))
{
ble.print("AT+BLEUARTTX=");
if (t_blink) {
ble.println("STATUS = BLINK");
}
else {
if (blinkState)
ble.println("STATUS = ON");
else
ble.println("STATUS = OFF");
}
}
if ((strcmp(ble.buffer, "ON") == 0))
{
blinkState = HIGH;
digitalWrite(LED_PIN, blinkState);
t_blink = 0;
ble.print("AT+BLEUARTTX=");
ble.println("ON");
}
if ((strcmp(ble.buffer, "OFF") == 0))
{
blinkState = LOW;
digitalWrite(LED_PIN, blinkState);
t_blink = 0;
ble.print("AT+BLEUARTTX=");
ble.println("OFF");
}
if ((strcmp(ble.buffer, "BLINK") == 0))
{
if (!t_blink) t_blink = millis();
ble.print("AT+BLEUARTTX=");
delay(50);
ble.println("BLINK");
}
//Terminal input to modify blink rate "Txxx"
if (ble.buffer[0] == 'T')//does terminal input start with "T"
{
//use memmove or create pointer and increment index to get to integer after 'T'
//memmove(ble.buffer, ble.buffer+1, strlen(ble.buffer));//strlen does not include null terminator
//int value = atoi(ble.buffer);
char *bufferString = ble.buffer;
bufferString++;
int value = atoi(bufferString);
BLINKTIME = value;
}
if (t_blink) {
if (t_blink > millis()) t_blink = millis();
if ((millis() - t_blink) > BLINKTIME) {
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
t_blink = millis();
}
}
}