Need help:Esp8266+433 mhz sockets+Blynk

Physical switches,because is the only way to know where is the problem.

I have added some lines the code,to use phisycal switches,for socket 1 ON and OFF,trying to emulate the virtual pins of Blynk,but as i said,i’m not good programming.and the sketch not compile good.
That’s is why i need help.

Thanks.

OK paste the sketch.

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
const int buttonPin = 0; //button in GPIO0
int buttonState = 0; //Initial state of button
//-------- rcswitch------
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();

char* socket1On = “010100000101010100110011”;
char* socket1Off = “010100000101010100111100”;
char* socket2On = “010100000101010111000011”;
char* socket2Off = “010100000101010111001100”;
char* socket3On = “010100000101011100000011”;
char* socket3Off = “010100000101011100001100”;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = “xxxxxxxxxxxxxxxxxxx”; //insert here your token generated by Blynk

void setup()
{
pinMode(buttonPin, INPUT);

// Serial.begin(9600);
// Blynk.begin(auth, “xxxxxxxxx”, “xxxxxxxxx”); //insert here your SSID and password

mySwitch.enableTransmit(2);
mySwitch.setPulseLength(187);
mySwitch.setProtocol(1);
}

void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {

mySwitch.send(socket1On);

}
else {
mySwitch.send(socket1Off);
}

Blynk.run();
}

I fix the errors at compiling,but i i have not tried yet. I think it need improvement,with some delay,etc.

Hi @cachofeiro,
This is how I have my 433mhz sockets working. You are welcome to try it. I set up buttons in the app as push mode, gave them a virtual pin no. and then used this code snippet to activate them. Works very well.

void loop()
{
  Blynk.run();
  timer.run();
  httpServer.handleClient();
}

/*Remote control of switches
-------------------------------------------------*/

  BLYNK_WRITE(0){
    mySwitch.send(354206,24);  //turn on switch 1B
  }
  BLYNK_WRITE(3){
    mySwitch.send(354198,24); //turn off switch 1B
  }
  BLYNK_WRITE(6){
    mySwitch.send(14331050,24); //turn on switch 3A
  }
  BLYNK_WRITE(7){
    mySwitch.send(14331042,24); //turn off switch 3A
  }
  BLYNK_WRITE(17){
    mySwitch.send(14331052,24); //turn on switch 2A
  }
  BLYNK_WRITE(18){
    mySwitch.send(14331044,24); //turn off switch 2A
  }

Ignore the httpServer.handleClient(); in the loop. That is for OTA updates. :slight_smile:

You can’t do it like that because it will try to send the RF OFF signal a thousand times a second in the loop(). The easy way is to set up a bool for the state of buttonPin and only send on or off when the state changes. The proper way is with attachInterrupt. Also physical momentary switches will send high and low with a single button press so you need to hold the switch on for a second or two before releasing it. If you don’t the on and off can be so close together they confuse your RF sockets.

Blynk have examples for everything including physical buttons. Do you know where all the examples are?

Maybe that was why you were seeing a pulse of twice the size of the required 187 microseconds.

I’ll try tomorrow mornig,and I’ll see what’s i can do.
Thanks.

Thanks for answer me.
Can you post complete sketch?
I must see it to figure out how i put my codes.My sockets don’t works with decimal codes,only binary or tristate.

Here you go…

/**************************************************************
 * Blynk is a platform with iOS and Android apps to control
 * Arduino, Raspberry Pi and the likes over the Internet.
 * You can easily build graphic interfaces for all your
 * projects by simply dragging and dropping widgets.
 *
 *   Downloads, docs, tutorials: http://www.blynk.cc
 *   Blynk community:            http://community.blynk.cc
 *   Social networks:            http://www.fb.com/blynkapp
 *                               http://twitter.com/blynk_app
 *
 * Blynk library is licensed under MIT license
 * This example code is in public domain.
 *
 **************************************************************
 * This example runs directly on ESP8266 chip.
 *
 * You need to install this for ESP8266 development:
 *   https://github.com/esp8266/Arduino
 *
 * Please be sure to select the right ESP8266 module
 * in the Tools -> Board menu!
 *
 * Change WiFi ssid, pass, and Blynk auth token to run :)
 *
 **************************************************************/
//28/10/2016 at 1.45pm
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
#include <RCSwitch.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <Wire.h>
#include <BaroSensor.h>
#include "DHT.h"
WidgetLED led(V1);
WidgetLCD lcd(V2);
WidgetLCD lcd1(V14);
#define DHTPIN 10
#define DHTTYPE DHT22
int reedSwitch = 12; // Reed Pin
int lightReading;
float light;
float husl = 50.00;  //Every 10 meters corresponds to 1.2 hPa pressure change at sea level. 
//This station is 433.42 above sea level so therefore add 52.01 hPa to reading then minus 2.01 to calibrate correctly
long rssi;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxx";
String mymin = " minutes";
const char* host = "esp8266-webupdate";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxxx";
char pass[] = "xxxxxxxxxxx";
RCSwitch mySwitch = RCSwitch();
DHT dht(DHTPIN,DHTTYPE,11);
SimpleTimer timer;
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;


void setup()
{
  WiFi.begin(ssid, pass);
  Blynk.begin(auth, ssid, pass);
  while (Blynk.connect() == false) { 
  // Wait until connected
}
  pinMode(reedSwitch,INPUT); // Garage Door Sensor Switch. Add External Pullup 1.5k OHM
  Serial.begin(9600);
  Wire.begin(2,14);
  BaroSensor.begin();
  dht.begin();
  mySwitch.enableTransmit(0); // Transmitter is connected to ESP8266 Pin #0
  
  MDNS.begin(host);
  httpUpdater.setup(&httpServer);
  httpServer.begin();
  MDNS.addService("http", "tcp", 80);
  Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser\n", host);
  timer.setInterval(10000L, sendAllData);// Here you set interval (10sec) and which function to call 
  timer.setInterval(1000L,garage);
  timer.setInterval(1000L, sendUptime); //  Here you set interval (1sec) and which function to call
  
}

void sendAllData()
{
    float t = BaroSensor.getTemperature();
    float pr = BaroSensor.getPressure();
    float p = pr + husl; //adjust barometer for height above sea level
    float h = dht.readHumidity();
    float f = dht.readTemperature();
    lightReading = analogRead(A0); 
    lightReading = map(lightReading,0,1023,0,100);   //Set the light reading to a pecentage of 100 with a 100% being full sun
    
    if (isnan(h) || isnan(f)) 
      {
        Serial.println("Failed to read from DHT sensor!");
        return;
      }
    
    if(!BaroSensor.isOK()) 
      {
        Serial.print("Sensor not Found/OK. Error: "); 
        Serial.println(BaroSensor.getError());
        BaroSensor.begin(); // Try to reinitialise the sensor if we can
      }
  else 
    {
      
      Serial.print("Temperature: "); 
      Serial.print(f);
      Serial.print("'C\t");
      Serial.print(" Pressure: ");
      Serial.print(p);
      Serial.println(" hPa");
      Serial.print("Humidity: "); 
      Serial.print(h);
      Serial.print("%\t");
      Serial.print(" Light: ");
      Serial.println(lightReading);
      
      Blynk.virtualWrite(V16,p);
      Blynk.virtualWrite(V13,lightReading );
      Blynk.virtualWrite(V10,f);
      Blynk.virtualWrite(V11,h);
    }
  }
  void sendUptime()
  {
    // This function sends Arduino up time every 1 second to Virtual Pin (V5)
    // In the app, Widget's reading frequency should be set to PUSH
    // You can send anything with any interval using this construction
    // Don't send more that 10 values per second

    Blynk.virtualWrite(V5, millis() / 1000);
    lcd.print(0,0,"Time connected");
    lcd.print(0,1, millis()/1000/60 + mymin);
    if (led.getValue()) {
      led.off();
    } 
    else {
      led.on();
    }
  }

  void garage(){
    int StatusSwitch = digitalRead(reedSwitch);
    if (StatusSwitch == HIGH)
  {
   Serial.println("Door is closed!");
    lcd1.print(0,0, "Garage door");
    lcd1.print(0,1, "is closed");
//    led2.off();
  }
   else   //if input is low (0), then door is open
  {
    Serial.println("Door is open!!");
//    Blynk.virtualWrite(V21,"open!!");
    lcd1.print(0,0, "Garage door");
    lcd1.print(0,1, "is open!!");
//    led2.on();
  }
  }

  BLYNK_WRITE(V22)
{
  rssi=WiFi.RSSI();   // This fn displays the Wifi strength when a button is pressed from the Blynk App
  int pinData = param.asInt(); 
  if(pinData==1)
  {
    lcd.clear();
    lcd.print(0 ,0,"Wifi Strength");   
    lcd.print(0 ,1,rssi);
  }
  
 }

    bool isFirstConnect = true; // Keep this flag not to re-sync on every reconnection

  // This function will run every time Blynk connection is established
  BLYNK_CONNECTED() 
  {
    if (isFirstConnect) 
    {
      // Request Blynk server to re-send latest values for all pins
//      Blynk.syncAll();
      // You can also update an individual Virtual pin like this:
      Blynk.syncVirtual(V10);
      Blynk.syncVirtual(V11);
      Blynk.syncVirtual(V13);
      Blynk.syncVirtual(V16);
      isFirstConnect = false;
    }
  }

void loop()
{
  Blynk.run();
  timer.run();
  httpServer.handleClient();
}

/*Remote control of switches
-------------------------------------------------*/

  BLYNK_WRITE(0){
    mySwitch.send(354206,24);  //turn on switch 1B
  }
  BLYNK_WRITE(3){
    mySwitch.send(354198,24); //turn off switch 1B
  }
  BLYNK_WRITE(6){
    mySwitch.send(14331050,24); //turn on switch 3A
  }
  BLYNK_WRITE(7){
    mySwitch.send(14331042,24); //turn off switch 3A
  }
  BLYNK_WRITE(17){
    mySwitch.send(14331052,24); //turn on switch 2A
  }
  BLYNK_WRITE(18){
    mySwitch.send(14331044,24); //turn off switch 2A
  }

It is still a work in progress so you can ignore most of it but you should be able to see how my 433mhz sockets work with decimal code.

@busa what make and model are your RF devices?

They are called Watts Clever here in Australia, made in China.

1 Like

HI !!
you’ve been reading my mind?.I live in Puerto Rico,but i travel frequently to Alabama,USA,so i left alone my house.and i need to leave protected.I’ve been looking for a complete system,with cameras,intrusion sensors,fire,co2,temperature and humidty sensors,remote sockets for lights and irrigation system,etc.I can build something similar,using your code.
I have a commercial alarm system,but not fill my needs.

Thank you too much.

Still do not know how,but i was able to run the code,without Blynk,and with the momentary switch.The codes i have sniffed with arduino nano and 433 mhz receiver,shows,that they are correct,but the pulse length not,354 microseconds.
I don’t understand,why setPulseLength do not works here,but in the SendDemo example do it.

Anyway,the problem is not in Blynk,so now what?.Any idea?

Thanks.

Sniff the details with the ESP.

sorry,what do you mean?

Set up the ESP to sniff the protocol with the ESP version (master branch not released sui77 library) to see if it gives the same results that you obtained with the Arduino.

Then use the same library to send the RF signal you get from sniffing the signal.

I’m sorry, but I had medical appointments, and I could not come here throughout the day.The problem is not in the library or the version of RcSwitch, because it is the same for the code SendDemo example, and works perfectly, sends the codes and pulse length correctly,and the sockets works fine,so…The fact is,RcSwitch no problem,Blynk no problem.

Tomorrow i´ll try another piece of code, and try to adapt it to my project, we’ll see…

Kind Regards.