NodeMCU + RC 433 + BLYNK

Hi all,since 3 weeks i had seamlessly working rc transmitter code on my NodeMCU.But it wasn’t just enough.I decided to upgrade the code and feed my board with small solar panel.Everything looks fine except one thing.For to observe my battery voltage i use simple timer,but during interval time device is going offline and i can not send any rc command.After couple of seconds i get able to control it.Can anybody point me what i’ve missed?

#define debug 1
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <SimpleTimer.h>
#include <RCSwitch.h>
#include <SPI.h>

#define BLYNK_PRINT Serial
#define PACKET_LENGTH 24

#define SWITCH_1_ON   5625156
#define SWITCH_1_OFF  5625153

#define SWITCH_2_ON   13976916
#define SWITCH_2_OFF  13976913

extern "C" {
#include "user_interface.h"
uint16 readvdd33(void);
int voltage = readvdd33();
}

RCSwitch mySwitch = RCSwitch();
WidgetTerminal terminal(V20);
WidgetLCD lcd(V19);
SimpleTimer timer;
IPAddress myip;

const int BlueLED =  D4;
long previousMillis = 0;
long interval = 1000;
int ledState = LOW;
int Led1=D8;
int Led2=D9;
long rssi;

const char* auth = "xxx";
const char* ssid     = "xxx";
const char* password = "xx";

void beep(unsigned char delayms)                                       //Just buzzer
{
  analogWrite(14, 20);
  delay(delayms);
  analogWrite(14, 0);
  delay(delayms);
}

void DataUpload()                           // Having issue with this part guys
{
  Blynk.virtualWrite(V14, millis() / 3600000);                // Uptime Hours
  Blynk.virtualWrite(V15, millis() / 60000);                   // Uptime Minutes
  Blynk.virtualWrite(V16,readvdd33());
  {
    terminal.println(F("---------------"));
    terminal.println(F("----NodeMCU----"));
    terminal.println(F("433 Transmitter"));
    terminal.println(F("by elanozturk"));
    terminal.flush();
  }
  if ((voltage < 3260) && (voltage > 3245))
  {
    Blynk.notify(String("433 Battery low: ") + voltage + ("mV"));
    terminal.println(String("433 Battery low: ") + voltage + ("mV"));
    terminal.flush();
    Blynk.email("oguz.serkan.ozturk@gmail.com", "NodeMCU 433", (String("Battery low: ") + voltage + (" mV")));
  }
  else if (voltage <= 3235)
  {
    Blynk.notify(String("433 Battery critical:") + voltage + ("mV"));
    terminal.println(String("433 Battery critical: ") + voltage + ("mV"));
    Blynk.email("oguz.serkan.ozturk@gmail.com", "433 NodeMCU", (String("Battery critical: ") + voltage + (" mV")));
  }
  terminal.flush();
}

void setup()
{
  beep(300);                                           //Buzzing
  beep(300);
  beep(50);
  beep(300);
  beep(300);
  Serial.begin(9600);
  Blynk.begin(auth, ssid, password);
  mySwitch.enableTransmit(16);
  unsigned long maxMillis=millis() + 8000;
  while ((Blynk.connect() == false) && ( millis() <= maxMillis)) {
  Serial.print("Houston we have a problem.");
  }
  pinMode(BlueLED, OUTPUT);                            //After get connected onboard blue led blinking
  myip = WiFi.localIP();
  Blynk.notify("NodeMCU 433 Started!");
  terminal.println("...Terminal opened...");
  terminal.flush();
  terminal.println(F("Blynk v" BLYNK_VERSION ));
  terminal.println(F("---------------"));
  terminal.println(F("----NodeMCU----"));
  terminal.println(F("433 Transmitter"));
  terminal.println(F("by elanozturk"));
  terminal.flush();
  timer.setInterval(30000L, DataUpload);
}

//******************************************************************
//        Turn once Switches ON/OFF
//******************************************************************
//### Action for Virtual Pin 0:     Switch 1 ON
BLYNK_WRITE(0) {
 mySwitch.send(SWITCH_1_ON, PACKET_LENGTH);
}

//### Action for Virtual Pin 1:     Switch 1 OFF
BLYNK_WRITE(1) {
  mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
}

//### Action for Virtual Pin 2:     Switch 2 ON
BLYNK_WRITE(2) {
  mySwitch.send(SWITCH_2_ON, PACKET_LENGTH);
}

//### Action for Virtual Pin 3:     Switch 2 OFF
BLYNK_WRITE(3) {
  mySwitch.send(SWITCH_2_OFF, PACKET_LENGTH);
}

//******************************************************************
//      Turn all Switches ON or OFF
//******************************************************************
//### Action for Virtual Pin 6:     All ON
BLYNK_WRITE(6) {
   mySwitch.send(SWITCH_1_ON, PACKET_LENGTH);
   delay(100);
   mySwitch.send(SWITCH_2_ON, PACKET_LENGTH);
   delay(100);
}
//### Action for Virtual Pin 7:     All OFF
BLYNK_WRITE(7) {
    mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
    delay(100);
    mySwitch.send(SWITCH_2_OFF, PACKET_LENGTH);
    delay(100);
}

BLYNK_WRITE(V20)
{
  if (String("Ssid") == param.asStr()) {
    terminal.println(String(ssid)) ;
    terminal.flush();
  }
  else if (String("Pass") == param.asStr()) {
    terminal.println(String(password)) ;
    terminal.flush();
  }
  else if (String("Auth") == param.asStr()) {
    terminal.println(String(auth)) ;
    terminal.flush();
  }
  else if (String("Volt") == param.asStr()) {
    terminal.println(String(voltage)) ;
    terminal.flush();
 } else {
    terminal.print("unknown command:");
    terminal.write(param.getBuffer(), param.getLength());
    terminal.println();
    terminal.flush();
  }
  terminal.flush();
}

BLYNK_WRITE(V8)                                                 // Wifi strength
{
 int pinData = param.asInt();
 if(pinData==1)
 {
   lcd.clear();
   lcd.print(0 ,0,"Wifi Strength");
   lcd.print(0 ,1,rssi);
 }else
 {
   lcd.clear();
 }
}

BLYNK_WRITE(V9)                                                    // IP Address
{
 int pinData = param.asInt();
 if(pinData==1)
 {
   lcd.clear();
   lcd.print(0 ,0,"IP ADDRESS:");
   String fullip = String(myip[0]) + "." + myip[1] + "." + myip[2] + "." + myip[3];
   lcd.print(0, 1, fullip);

 }else
 {
   lcd.clear();
 }

}

//******************************************************************
//        Endless Loop (main() function)
//******************************************************************

void loop()
{
  Blynk.run();
  timer.run();
  rssi=WiFi.RSSI();
  myip=WiFi.localIP();
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis > interval)
  {
    previousMillis = currentMillis;
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    digitalWrite(BlueLED, ledState);
  }
}
1 Like

this looks weird? why is there {} there?

Really don’t know why but it works like charm,i just grabbed that from some sketch.
Maybe @Costas can enlight us :slight_smile:

@elanozturk the {} is just the standard syntax for code contained within a function and in this case it is to use some regular C code provided by Espressif in the Arduino C++ environment.

Are you using the latest release of RCSwitch or the master branch? There are some ESP “fixes” in the master branch that are not included in the latest release. Try the master branch, if you are not already using it, and let us know if you still have problems.

@Costas I’m going to check the latest library but i think my problem is not related that. While DataUpload function device disappears from blynk app for few seconds and it repeats in every 30 seconds because of function interval time.I set interval because i didn’t want to flood server.

I tried it with lastest version and master branch and still having the same problem :confused:

Your sketch works fine on my WeMos. Suspect you have wired up something incorrectly.

Show schematic for your project.

Well,without attach my board to breadboard and transmitter module have same issue ,and i also tried to connect transmitter module with jumper wires directly and also with different pin. I transmit signal smoothly except during data upload period because app says device is offline.

You mentioned “solar”. How is this connected?

My WeMos doesn’t go offline during the dataUpload() function.

Solar connection ok but with this issue i couldn’t deploy it.I’m going to record my app screen.

@Costas After remove that part from the code;

> if ((voltage < 3260) && (voltage > 3245))
>   {
>     Blynk.notify(String("433 Battery low: ") + voltage + ("mV"));
>     terminal.println(String("433 Battery low: ") + voltage + ("mV"));
>     terminal.flush();
>     Blynk.email("oguz.serkan.ozturk@gmail.com", "NodeMCU 433", (String("Battery low: ") + voltage + (" mV")));
>   }
>   else if (voltage <= 3235)
>   {
>     Blynk.notify(String("433 Battery critical:") + voltage + ("mV"));
>     terminal.println(String("433 Battery critical: ") + voltage + ("mV"));
>     Blynk.email("oguz.serkan.ozturk@gmail.com", "433 NodeMCU", (String("Battery critical: ") + voltage + (" mV")));
>   }
>   terminal.flush();

everything got better.

The code you removed works fine on my WeMos.

I did notice that in your original sketch you have > 3245 and <= 3235. So you are not covering >3235 and <= 3245. Think the <= 3235 should be <= 3245. I don’t think that’s your problem though.

What voltage does your system read? I get around 2700mV on my WeMos.

Looking at your video I see you have a similar voltage of around 2780mV.

So the else statement will kick in at each loop interval but if this is set at 30s it should be ok (it can’t be any less than 15s as that is the current minimum time allowed between push and email messages).

From pc usb i get always around 2780 mV .Most likely the issue is about to voltage coverage .I’m going to try to fix it.Thank you @Costas!