I originally got argon to 2 xenon mesh network communication. Since Particle is going away from using the mesh network and xenons, I’m now trying to take a crack out of argon to argon communication using the BLE mesh library from this link: https://support.particle.io/hc/en-us/articles/360044755894-Create-a-local-publish-subscribe-group-using-BLE-on-Gen3-devices .
I’m trying to do this without connecting to cloud. My application is creating biometric motion sensors using accelerometers. My code is below.
Peripheral:
/*
* Project peripheral_test
* Description: Particle Argon BLE peripheral test
* Author: Cameron Pinnock
* Date: 7/14/2020
*/
#include "Particle.h"
#include <limits.h>
#include "BLE_Group.h"
#include <Adafruit_BNO055.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
// This strips the path from the filename
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
BLE_Group *group;
//SYSTEM_THREAD(ENABLED);
//SYSTEM_MODE(SEMI_AUTOMATIC);
const unsigned long UPDATE_INTERVAL = 10;
unsigned long lastUpdate = 0;
//Message variables
char beatMsg[128];
char ackMsg[128];
Adafruit_BNO055 bno; //Adafruit_BNO055(0x28 );
char accVal_beta[128];
int accel_valy;
void setup()
{
Serial.begin(115200);
while (!bno.begin())
{
Serial.println("BNO sensor not available");
}
group = new BLE_Group_Peripheral(1); // The parameter is the groupID
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - lastUpdate >= UPDATE_INTERVAL)
{
lastUpdate = millis();
sensors_event_t event;
bno.getEvent(&event);
accel_valy=event.orientation.y;
//accel_valy=event.orientation.y;
//accel_valz=event.orientation.z;
snprintf(accVal_beta, 128, "%d", accel_valy);
Serial.println(accel_valy);
//Particle.publish("Beta_Accelerameter", String(accVal_beta), PRIVATE);
group->publish("accVal_beta001", accVal_beta);
}
}
Central:
/*
* Project peripheral_test
* Description: Particle Argon BLE central test
* Author: Cameron Pinnock
* Date: 7/14/2020
*/
#include "Particle.h"
#include <limits.h>
#include "BLE_Group.h"
#include <Adafruit_BNO055.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
// This strips the path from the filename
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
BLE_Group *group;
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
const unsigned long UPDATE_INTERVAL = 10;
unsigned long lastUpdate = 0;
//Message variables
char beatMsg[128];
char ackMsg[128];
Adafruit_BNO055 bno; //Adafruit_BNO055(0x28 );
int accelVal_alpha;
int val;
char biometricPacket[128];
void biometricData(const char *event, const char *data){
unsigned long currentMillis = millis();
if (currentMillis - lastUpdate >= UPDATE_INTERVAL)
{
int accelVal_beta = atoi(data);
sensors_event_t event2;
bno.getEvent(&event2);
accelVal_alpha = event2.orientation.y;
snprintf(biometricPacket, 128, "%d %d ", accelVal_beta, accelVal_alpha);
Serial.println(biometricPacket);
}
}
void setup()
{
Serial.begin(115200);
while (!bno.begin())
{
Serial.println("BNO sensor not available");
}
//group = new BLE_Group_Central(1); // The parameter is the groupID
//group->subscribe("accVal_beta001", biometricData);
}
void loop()
{
unsigned long currentMillis = millis();
if (currentMillis - lastUpdate >= UPDATE_INTERVAL)
{
//int accelVal_beta = atoi(data);
sensors_event_t event2;
bno.getEvent(&event2);
accelVal_alpha = event2.orientation.y;
Serial.println(accelVal_alpha);
//snprintf(biometricPacket, 128, "%d %d ", accelVal_beta, accelVal_alpha);
//Serial.println(biometricPacket);
}
}