Multiple dashboards with one device?

I have a single Particle with possibly any number sensor clusters attached. I would like each cluster to be a separate blynk dashboard/project with different auth strings for each cluster. Is there a way to define multiple Blynk objects and treat them as separate classes?

Karl

I think it’s possible to use multiple Auth tokens on a device. I seem to remember someone doing that here. Have you tried the search for multiple auth token?

What hardware is this?

Particle Photon.

Yes, I’ve done some searching, and there’s a lot of “it should work” or no responses to others. nothing useful so far.

the best example is from over a year ago and involves having to disconnect and reconnect for every time you want to switch auth tokens. I was hoping maybe something a bit more elegant would exist for a years worth of development.

just a little background, I have two classes setup. Each class is declared twice. One class manages the sensor cluster and pulls updates on a separate timer.

The second class is to manage the blynk project, for which will have it’s own timer to wake up, do the Blynk.run(); and all the things you would typically do in loop() to service the blynk project.

I’ve at least got it compiling and able to run the POC code. It seems to connect, but then times out.

//include "blynk/blynk.h"
#define BLYNK_DEBUG // Optional, this enables lots of prints
#define BLYNK_PRINT Serial
#include "blynk/BlynkParticle.h"


STARTUP(
    WiFi.selectAntenna(ANT_AUTO)   // Auto select antenna for best coverage
    );

class randomSensor {
    public:
        int sensor1, sensor2;
        randomSensor() {
            sensor1 = 0;
            sensor2 = 0;
        }
        
        void collectReadings() {
            sensor1 = random(0,100);
            sensor2 = random(0,100);
        }
};

class BlynkDashboard {
    private:
        String auth;
        randomSensor* Sensor;
        int someSetting;
        bool firstConnect = true;
        BlynkTransportParticle _blynkTransport;
        BlynkParticle* Blynk;

    public:
        BlynkDashboard(randomSensor *tmpSensor, String authStr) {
            auth = authStr;
            Serial.println("New Blynk Dashboard declaired");
            Sensor = tmpSensor;
            someSetting = 0;

            Blynk = new BlynkParticle(_blynkTransport);
            Blynk->begin(auth);
        }

        BLYNK_CONNECTED()
        {
            digitalWrite(D7, LOW);
            if (firstConnect) {
                Blynk->syncAll();
                firstConnect = false;
            }
        }
        
        BLYNK_DISCONNECTED()
        {
            digitalWrite(D7, HIGH);
        }

        BLYNK_WRITE(V10)
        {
            someSetting = param.asInt();
            sprintf(msg, "Setting changed to %d", someSetting);
            Serial.print(msg);
        }

        void blynkService() {
            Blynk->virtualWrite(V0, Sensor->sensor1);
            Blynk->virtualWrite(V1, Sensor->sensor2);
            Blynk->run();
            Serial.println("dash callback");
        }
};

// system defines
#define SAMPLE_INTERVAL   200           // How often to pull data from the sensors
#define UPDATE_INTERVAL   500           // How often to update the dashboard

void setup()
{
    Serial.begin(9600);
    String auth;

    // setup Blynk conneciton LED
    pinMode(D7, OUTPUT);
    digitalWrite(D7, HIGH);

    auth = "2345";
    static randomSensor sensor1;
    static BlynkDashboard sensor1Dash(&sensor1, auth);
    static Timer sensor1Timer(SAMPLE_INTERVAL, &randomSensor::collectReadings, sensor1);
    static Timer sensor1DashTimer(UPDATE_INTERVAL, &BlynkDashboard::blynkService, sensor1Dash);
    sensor1Timer.start();
    sensor1DashTimer.start();

    auth = "1234";
    static randomSensor sensor2;
    static BlynkDashboard sensor2Dash(&sensor2, auth);
    static Timer sensor2Timer(SAMPLE_INTERVAL, &randomSensor::collectReadings, sensor2);
    static Timer sensor2DashTimer(UPDATE_INTERVAL, &BlynkDashboard::blynkService, sensor2Dash);
    sensor1Timer.start();
    sensor1DashTimer.start();

    Serial.println("setup() - complete");
}