I’d like to set the initial state and value of some widgets such as led on/off, display, properties but its not working for me. Is there a Blynk.isRunning(project_name) type of function? What is the best practice for doing this?
I’m open for suggestions on what I’m doing wrong or a different way to approach it.
Hardware and libraries:
Nexus 6 with Android 7.0 installed
Sparkfun RedBoard (Uno clone)
Adafruit BlueFruit LE Shield – This could once again be an issue with BLE?
Big Easy Driver (stepper motor driver – not used in this sketch, but is connected)
Blynk library v0.3.10
Here are the things I tried. The complete sketch is at the end of the post
My first thought is to put them in setup()
void setup()
{
// other setup stuff
Blynk.virtualWrite(V0, 101);
Blynk.setProperty(V0, "label", "What Animal?");
Blynk.setProperty(V0, "color", "#99FFFF");
}
Doesn’t work.
So I tried waiting for connections
void setup()
{
// other setup stuff
while (!Blynk.connected() && !ble.isConnected())
{ delay(2000); }
Blynk.virtualWrite(V0, 101);
Blynk.setProperty(V0, "label", "What Animal?");
Blynk.setProperty(V0, "color", "#99FFFF");
}
Still no joy.
So then I try moving the settings into a function and calling it from setup
void setup()
{
// other setup stuff
while (!Blynk.connected() && !ble.isConnected())
{ delay(2000); }
startvalues();
}
Still doesn’t work, but if I start it after a delay.
SimpleTimer timer;
int delay_start = timer.setTimeout(100, startValues);
void setup()
{
// other setup stuff
while (!Blynk.connected() && !ble.isConnected())
{ delay(2000); }
timer.restartTimer(delay_start);
}
it somewhat works. The colors and labels are set, but only the setProperty lines.
The only way I can get the value itself to be set is if the dashboard is running.
Any ideas?
Here is the complete sketch.
/////////////////////////////////////
//
// V2 labeledValue, freq = push
// BLE module
// #define BLYNK_DEBUG
#define BLYNK_PRINT Serial
#define BLYNK_USE_DIRECT_CONNECT // If trouble connecting trying commenting out
#include <SimpleTimer.h>
#include <SPI.h>
#include <SoftwareSerial.h>
// BLE
#include <BlynkSimpleSerialBLE.h>
// Adafruit Bluefruit LE Shield which using SPI
#include <Adafruit_BLE.h>
#include <Adafruit_BluefruitLE_SPI.h>
#define BLUEFRUIT_SPI_CS 8
#define BLUEFRUIT_SPI_IRQ 7
#define BLUEFRUIT_SPI_RST 4
#define BLUEFRUIT_VERBOSE_MODE false
Adafruit_BluefruitLE_SPI ble(BLUEFRUIT_SPI_CS, BLUEFRUIT_SPI_IRQ, BLUEFRUIT_SPI_RST);
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxx";
int cats = 0;
void startValues()
{
Serial.println("Enter startValues()");
Blynk.virtualWrite(V0, 171);
Blynk.setProperty(V0, "label", "What Animal?");
Blynk.setProperty(V0, "color", "#0099FF");
Serial.println("Exit startValues()");
}
SimpleTimer timer;
int delay_start = timer.setTimeout(100, startValues);
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ble);
ble.begin(BLUEFRUIT_VERBOSE_MODE);
ble.factoryReset(); // Optional but advisable
ble.setMode(BLUEFRUIT_MODE_DATA);
while (!Blynk.connected() && !ble.isConnected())
{
delay(2000);
}
Serial.println("All connected");
timer.restartTimer(delay_start);
// startValues();
// Blynk.setProperty(V0, "label", "What Animal?");
// Blynk.setProperty(V0, "color", "#99FFFF");
// Blynk.virtualWrite(V0, 101);
}
void loop()
{
Blynk.run();
timer.run();
}