I have some connect issues and i dont get why.
What could it be exempt for the ssid Password in Auth?
3 posts were split to a new topic: I added a sunrise alarm clock function which is controlled by the new eventor widget, but now Wemos crashes multiple time a night
hi sir/madam i am beginner with blynk
can i get app that you designed for this code
Hi,
I have changed the concept of all my IoTās and decided to use Blynk only indirectly. This means that all my microprocessors are running without Blynk but communicate with MQTT instead in order to better integrate them into my home automation system. I run Blynk only on one dedicated ESP01. With this instance I control many IoTās also the Wemos D1 of my Stonelamp. It basically uses the Blynk GUI to publish MQTT messages only. The newest Stonelamp code (V2) can be downloaded from github:
Stonelanp V2
The Blynk - MQTT bridge code is here:
/*
Blynk to MQTT bridge
Version 1.1 24.April 2018 added Spot and Shells
Version 1.0 9. Feb 2018
Funtion: Use Blynk GUI to control MQTT attached devices
Pin assignments:
* ESP01
Blynk Virtual Pins: 127 pins available
1. kitchen top (Arilux LC01 running Tasmota)
V0: ON OFF Button
V1: Dimmer slider
V2: Speed slider
V3: Color select
V4: Fade switch
V5: Scheme slider
2. Kitchen board (ESP01 running Tasmota)
V6: ON OFF Button
3. Stonelamp (Wemos D1 mini running my own stuff)
V7: ON OFF Button
V8: Blink On/Off
V9: Color select
V10: Activity slider
V11: Brightness slider
V12: Speed slider
4. For own purposes (ESP01 running Blynk)
V13: ON OFF LED
V14: UP LED
5. Spot (Sonoff Basic running Tasmota)
V15: ON OFF Button
6. Mussels (Wemos D1 mini running my own stuff)
V16: ON OFF Button
V17: Blink On/Off
V18: Color select
V19: Activity slider
V20: Brightness slider
V21: Speed slider
Bill of material:
-ESP01 ESP8266 and appropriate 3.3V Power
-1000uF capacitor (I found that a capacitor around 5V and Ground increases stability of the Wemos D1)
-5V 750mA Power Supply
*/
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
// Set ESP8266 Serial object
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
SimpleTimer timer;
// Blynk
//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial
int ONOFF_LED = V13;
int UP_LED = V14;
long int last_UP_change = millis();
bool runn = 1;
bool lamp_on;
int brightness;
int current_activity;
int standard_speed;
int counter = 0;
// Wireless settings
const char AUTH[] = "656476457475656858548678686";
const char SSID[] = "******";
const char PASSWORD[] = "*******";
IPAddress mqtt_server(192,168,178,59);
const char* mqtt_username = "mqtt";
const char* mqtt_password = "****";
char* InTopic = "tele/arilux74/STATE"; //subscribe to topic to be notified about
char* InTopic1 = "tele/ESP71/STATE";
char* Stonelamp = "Stonelamp";
char* Shells = "Shells";
WiFiClient espClient;
PubSubClient client(espClient);
void setup() {
Serial.begin(115200);
Serial.println(F("setup start"));
//Blynk
WiFi.mode(WIFI_STA);
Blynk.begin(AUTH, SSID, PASSWORD,"192.168.178.59",8442);
while (Blynk.connect() == false) { // Wait until connected
if ((millis() - last_UP_change) > 30000) { // 30s before reset
Serial.println(F("resetting"));
ESP.restart();
}
}
wait(10);
client.setServer(mqtt_server, 8883);
client.setCallback(callback);
//OTA
// Port defaults to 8266
// ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID]
ArduinoOTA.setHostname("ESP43-MQTT_Bridge");
// No authentication by default
ArduinoOTA.setPassword((const char *)"***");
ArduinoOTA.onStart([]() {
Serial.println("Start");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println(F("Entering loop"));
wait(200);
timer.setInterval(1001L, blinkonoff);
Blynk.virtualWrite(ONOFF_LED,0);
Blynk.virtualWrite(UP_LED,0);
}
void loop() {
Blynk.run();
if(!Blynk.connected()) {
Serial.println(F("Resetting in loop"));
ESP.restart();
}
timer.run();
if (!client.connected()) {
reconnect();
}
client.loop();
ArduinoOTA.handle();
}
void wait (int ms) {
long current_time = millis();
long end_time = current_time + ms;
while (current_time < end_time) {
current_time = millis();
}
}
void blinkonoff(){
// Turn runn LED on/off
Blynk.virtualWrite(UP_LED,runn * 255); // turn Up off
runn = !runn;
last_UP_change = millis();
}
//Kitchen top
BLYNK_WRITE(V0) { //ON Off switch
if (param.asInt()) {
client.publish("cmnd/arilux74/power","1");
lamp_on = 1;
}
else {
client.publish("cmnd/arilux74/power","0");
lamp_on = 0;
}
Blynk.virtualWrite(ONOFF_LED,lamp_on * 255);
}
BLYNK_WRITE(V1) { // Dimmer 0-100
brightness = param.asInt();
char bright[4];
dtostrf(brightness, 3, 0, bright);
client.publish("cmnd/arilux74/Dimmer",bright);
}
BLYNK_WRITE(V2) { // Speed 0-100
standard_speed = param.asInt();
char new_speed[4];
dtostrf(standard_speed, 3, 0, new_speed);
client.publish("cmnd/arilux74/speed",new_speed);
}
BLYNK_WRITE(V3) { //Color select 0-255 each
char hex[7] = {0};
sprintf(hex,"%02X%02X%02X",param[0].asInt(),param[1].asInt(),param[2].asInt()); //convert to an hexadecimal string. Lookup sprintf for what %02X means.
client.publish("cmnd/arilux74/color",hex);
}
BLYNK_WRITE(V4) { // Fade switch
if (param.asInt()) client.publish("cmnd/arilux74/fade","1");
else client.publish("cmnd/arilux74/fade","0");
}
BLYNK_WRITE(V5) { //Scheme slider 0-4
current_activity = param.asInt();
char activity[2];
dtostrf(current_activity, 1, 0, activity);
client.publish("cmnd/arilux74/scheme",activity);
}
//Kitchen Board
BLYNK_WRITE(V6) { //ON Off Board
if (param.asInt()) {
client.publish("cmnd/ESP71/power","1");
}
else {
client.publish("cmnd/ESP71/power","0");
}
}
//Stonelamp
BLYNK_WRITE(V7) { //ON Off Stonelamp
if (param.asInt()) publish(Stonelamp,"Power",1);
else publish(Stonelamp,"Power",0);
}
BLYNK_WRITE(V8) { //Blink ON Off Stonelamp
if (param.asInt()) publish(Stonelamp,"Blink",1);
else publish(Stonelamp,"Blink",0);
}
BLYNK_WRITE(V9) { //Color select 0-255 each Stonelamp
long current_color = param[2].asInt() + 256*param[1].asInt() + 256*256*param[0].asInt();
publish(Stonelamp,"Color",current_color);
}
BLYNK_WRITE(V10) { //Scheme slider 0-12 Stonelamp
current_activity = param.asInt();
publish(Stonelamp,"Scheme",current_activity);
}
BLYNK_WRITE(V11) { // Brightness Stonelamp 0-255
brightness = param.asInt();
publish(Stonelamp,"Dimmer",brightness);
}
BLYNK_WRITE(V12) { // Speed 100-1 Stonelamp
standard_speed = param.asInt();
publish(Stonelamp,"Speed",standard_speed);
}
//Spot
BLYNK_WRITE(V15) {
}
//Shells
BLYNK_WRITE(V16) { //ON Off Stonelamp
if (param.asInt()) publish(Shells,"Power",1);
else publish(Shells,"Power",0);
}
BLYNK_WRITE(V17) { //Blink ON Off Stonelamp
if (param.asInt()) publish(Shells,"Blink",1);
else publish(Shells,"Blink",0);
}
BLYNK_WRITE(V18) { //Color select 0-255 each Stonelamp
long current_color = param[2].asInt() + 256*param[1].asInt() + 256*256*param[0].asInt();
publish(Shells,"Color",current_color);
}
BLYNK_WRITE(V19) { //Scheme slider 0-12 Stonelamp
current_activity = param.asInt();
publish(Shells,"Scheme",current_activity);
}
BLYNK_WRITE(V20) { // Brightness Stonelamp 0-255
brightness = param.asInt();
publish(Shells,"Dimmer",brightness);
}
BLYNK_WRITE(V21) { // Speed 100-1 Stonelamp
standard_speed = param.asInt();
publish(Shells,"Speed",standard_speed);
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("BlinkMQTTBridge",mqtt_username,mqtt_password)) {
Serial.println("connected");
counter = 0;
// ... and resubscribe
client.subscribe(InTopic);
client.subscribe(InTopic1);
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 0.3 second");
++counter;
if (counter > 180) ESP.reset();
// Wait .3 seconds before retrying
delay(300);
ArduinoOTA.handle();
}
}
}
void callback(char* topic, byte* payload, unsigned int length) {
StaticJsonBuffer<450> jsonBuffer;
//const char* json = "{"Time":"2018-02-09T14:55:30","Uptime":1,"Vcc":3.180,"POWER":"ON","Dimmer":73,"Color":"BA3E00","Scheme":0,"Fade":"OFF","Speed":1,"LedTable":"OFF","Wifi":{"AP":1,"SSId":"mmwireless","RSSI":66,"APMac":"0E:41:58:01:03:F0"}}";
JsonObject& root = jsonBuffer.parseObject((char*)payload);
const char* Time = root["Time"]; // "2018-02-09T14:55:30"
int Uptime = root["Uptime"]; // 1
float Vcc = root["Vcc"]; // 3.18
const char* POWER = root["POWER"]; // "ON"
int Dimmer = root["Dimmer"]; // 73
const char* Color = root["Color"]; // "BA3E00"
int Scheme = root["Scheme"]; // 0
const char* Fade = root["Fade"]; // "OFF"
int Speed = root["Speed"]; // 1
//here you can use this information (optional)
}
void publish(char* target, char* command, long argument){
//{"CMD":"Speed","ARG":29}
char output[90];
snprintf_P(output, sizeof(output), PSTR("{\"CMD\":\"%s\",\"ARG\":%d}"),command,argument);
client.publish(target,output);
}
Yay! another one comes over to the dark side!
Have you thought about using Node-Red as your Blynk to MQTT bride, as Node-Red gives really easy integration with other things such as Amazon Alexa.
Pete.
Yes, I do use node-red combined with āNode-RED Alexa Home Skill Bridgeā, a free service which allows ON/OFF, asking for a temperature, or +/- dimming levels, asking if a door is locked, etc.
Over time I found I need several interfaces to control my IoTās. My wife likes Blynk as a GUI, but also physical switches (usually I use 433MHz wall switches). I like Alexa better but I also use Domoticz to increase automation.
hi i need app for this code can you provide it
Hi, Iām new here and I want to learn more about Blynk.
I want to put the led on the ceilling.
But I want to put one Button to On/Off and another Button to change the effects, in your project have only one Button to change effects?
I am from Brazil, Sorry for my English.