RF 433 Mhz on virtual pin doesn't want to send (with scheduling)

After running the MCU for two weeks or so with a new transmitter I’m quite happy with the result. I think it was just once my lamp didn’t start as scheduled. This however, is almost certain due to poor reception or transmission because my terminal did log it as “Schedule 1 started”. To add some extra redundancy to the schedule function (well, actually the RF system) I’m invoking Blynk.syncVirtual(V0); and not just the send command and a virtualWrite as before.

The code:

/******************************************************************************

Both NexaSelfLearningTransmitter.h and NexaSelfLearningReceiver.h uses
"transmitter" as a variable, so I had to change one in order to compile.
NexaSelfLearningReceiver.h now uses "transmitter2".

*******************************************************************************/
#define BLYNK_PRINT Serial
#include "NexaSelfLearningTransmitter.h"
#include "NexaSelfLearningReceiver.h"
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

#define W5100_CS		    10	// SD-card
#define SDCARD_CS		    4
#define RX_PIN          2
#define RX_LED          0 	// Reduces the no of error msg when compiling (NULL is char 0?)
#define TX_PIN          8
#define TX_LED          0
#define TRANSMITTER_ID  1912830

NexaSelfLearningTransmitter transmitter = NexaSelfLearningTransmitter(TX_PIN, TX_LED);
NexaSelfLearningReceiver receiver = NexaSelfLearningReceiver(RX_PIN, RX_LED);	// Actually, not used yet

bool on = false;
bool group = false;
short dim = 0;
uint8_t channel = 0;
uint64_t receivedSignal = 0;
//uint32_t transmitter = 0; // same as TRANSMITTER_ID 
uint32_t transmitter2 = 0;  

WidgetTerminal terminal(V4);
BlynkTimer timer;
WidgetRTC rtc;
char currentTime[9];

byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xCC };
IPAddress arduino_ip (192, 168,   0,  20);        
IPAddress dns_ip     (192, 168,   0,   1);
IPAddress gateway_ip (192, 168,   0,   1);
IPAddress subnet_mask(255, 255, 255,   0);

char auth[] = ""; 			// Token for Blynk

bool clockSync = false;

void setup() {

	pinMode(SDCARD_CS, OUTPUT);	// Deselect the SD card
	digitalWrite(SDCARD_CS, HIGH);
	Serial.begin(9600);
	Serial.println();
	Blynk.begin(auth, "cloud.blynk.cc", 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
	
	while (Blynk.connect() == false) {
		// Wait until connected
	}
	
	for (int i = 0; i <= 24; i++) {
		terminal.println("");	// "clear screen" in app.
	}
	
	terminal.flush();
	terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
	terminal.println(F("-------------"));
	terminal.flush();
	timer.setInterval(60000L, activetoday);		// check every 60s if ON / OFF trigger time has been reached
	timer.setInterval(30000L, reconnectBlynk);	// check every 30s if still connected to server
	timer.setInterval(1000L, clockDisplay);		// check every second if time has been obtained from the server
}

BLYNK_CONNECTED() {
	rtc.begin();
}

void activetoday(){         		// check if schedule #1 or #2 should run today
	if(year() != 1970){
		Blynk.syncVirtual(V10);		// sync scheduler #1
	}
}

void clockDisplay(){				// only needs to be done once after time sync
	if((year() != 1970) && (clockSync == false)){
		sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
		Serial.println(currentTime);
		terminal.println(currentTime);
		terminal.flush();
		clockSync = true;
	}
}

BLYNK_WRITE(V10) {   // Scheduler #1 Time Input widget

	TimeInputParam t(param);
	unsigned int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
	unsigned int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
	unsigned int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
	int dayadjustment = -1;
	if(weekday() == 1){
		dayadjustment = 6; // needed for Sunday Time library is day 1 and Blynk is day 7
	}
	if(t.isWeekdaySelected((weekday() + dayadjustment))){ //Time library starts week on Sunday, Blynk on Monday
		//Schedule is ACTIVE today
		if(nowseconds >= startseconds - 31 && nowseconds <= startseconds + 31 ){    // 62s on 60s timer ensures 1 trigger command is sent
			transmitter.deviceOn(TRANSMITTER_ID, 15);	// Doesnt always work for some reason 
			Blynk.virtualWrite(V0, 1);					// This however always work as long as everything is online
			Blynk.syncVirtual(V0);						
			Serial.println("Schedule 1 started");
			terminal.println("Schedule 1 started");
			terminal.flush();
    }
		if(nowseconds >= stopseconds - 31 && nowseconds <= stopseconds + 31 ){   // 62s on 60s timer ensures 1 trigger command is sent
			transmitter.deviceOff(TRANSMITTER_ID, 15);
			Blynk.virtualWrite(V0, 0);
			Blynk.syncVirtual(V0);  
			Serial.println("Schedule 1 finished");
			terminal.println("Schedule 1 finished");
			terminal.flush();
		}
	}
}

BLYNK_WRITE(V0) {                   // Unit 1 (Remote Controller 1)

	if ( param.asInt() == 1 ) {     
		transmitter.deviceOn(TRANSMITTER_ID, 15);
		Serial.println("RC 1 ON");
		terminal.println("RC 1 ON");
		terminal.flush();
	}
	else {                          
		transmitter.deviceOff(TRANSMITTER_ID, 15);
		Serial.println("RC 1 OFF");
		terminal.println("RC 1 OFF");
		terminal.flush();
	}
}

BLYNK_WRITE(V1) {                    // Unit 2

	if ( param.asInt() == 1 ) {
		transmitter.deviceOn(TRANSMITTER_ID, 14);
		Serial.println("RC 2 ON");
		terminal.println("RC 2 ON");
		terminal.flush();
	}
	else {
		transmitter.deviceOff(TRANSMITTER_ID, 14);
		Serial.println("RC 2 OFF");
		terminal.println("RC 2 OFF");
		terminal.flush();
	}
}

BLYNK_WRITE(V2) {					// Unit 3

	if ( param.asInt() == 1 ) {
		transmitter.deviceOn(TRANSMITTER_ID, 13);
		Serial.println("RC 3 ON");
		terminal.println("RC 3 ON");
		terminal.flush();
	}
	else {
		transmitter.deviceOff(TRANSMITTER_ID, 13);
		Serial.println("RC 3 OFF");
		terminal.println("RC 3 OFF");
		terminal.flush();
	}
}

BLYNK_WRITE(V3) {                    // Group, all units

	if ( param.asInt() == 1 ) {
		transmitter.groupOn(TRANSMITTER_ID);
		Blynk.virtualWrite(V0, 1);    
		Blynk.virtualWrite(V1, 1);    
		Blynk.virtualWrite(V2, 1);
		Serial.println("ALL IS ON");
		terminal.println("ALL IS ON");
		terminal.flush();
	}
	else {
		transmitter.groupOff(TRANSMITTER_ID);
		Blynk.virtualWrite(V0, 0);    
		Blynk.virtualWrite(V1, 0);
		Blynk.virtualWrite(V2, 0);
		Serial.println("ALL IS OFF");
		terminal.println("ALL IS OFF");
		terminal.flush();
	}
}

void reconnectBlynk() {

	if (!Blynk.connected()) {
		if(Blynk.connect()) {
		  BLYNK_LOG("Reconnected");
		}
		else {
		  BLYNK_LOG("Not reconnected");
		}
}	
}

void loop() {

	if(Blynk.connected()) {
		Blynk.run();
	}
	timer.run();
}

/***************************************************************************
void data_incoming() {
      receivedSignal = receiver.receiveSignal(&transmitter2, &on, &group, &channel, &dim, 1000);
      if(receivedSignal != 0) {
            if (channel == 15) {               	// Unit 1
                  Blynk.virtualWrite(V0, on);  	// on == 1 || 0
                  Blynk.syncVirtual(V0);       
            }
            else if (channel == 14) {			// Unit 2
                  Blynk.virtualWrite(V1, on);
                  Blynk.syncVirtual(V1);      
            }
            else if (channel == 13) {			// Unit 3
                  Blynk.virtualWrite(V2, on);
                  Blynk.syncVirtual(V2);
            }
            else if (group == 1) {
            	if (on == 1 ) {
					transmitter.groupOn(TRANSMITTER_ID);
					Blynk.virtualWrite(V0, 1);    
					Blynk.virtualWrite(V1, 1);    
					Blynk.virtualWrite(V2, 1);
					Blynk.syncVirtual(V0, V1, V2);
				}
				else {
					transmitter.groupOff(TRANSMITTER_ID);
					Blynk.virtualWrite(V0, 0);    
					Blynk.virtualWrite(V1, 0);
					Blynk.virtualWrite(V2, 0);
					Blynk.syncVirtual(V0, V1, V2);
				}
            }
            else {
                  Serial.println("Not my remote controller?");
            }
            Serial.print("Recieved a signal: ");
            Serial.print("transmitter_id="); Serial.print(transmitter2);
            Serial.print(", group="); Serial.print(group);
            Serial.print(", on="); Serial.print(on);
            Serial.print(", channel="); Serial.print(channel);
            Serial.print(", dim="); Serial.print(dim);
            Serial.println("");
            terminal.println("Recieved a signal!");
            terminal.flush();      
      }
}
***************************************************************************/

My next challenge is to implement a receiver that updates the Blynk app (and perhaps retransmit) when wall mounted RF-switches or remote controllers are used. For this to work I think I need to get a LoRa transceiver. The cheap XY-MK-5V receivers that I’ve done some testing with is, by design, worthless!

Suggestion for a Blynk appropriate ESP board with matching LoRa module would be much appreciated! :slightly_smiling_face:

@Costas thanks for the code and help! Guessing the category could be changed to “Solved” or “Awaiting new hardware” :wink:

To whom it may concern… or have some interest in my doings :slight_smile:

Although many LoRa transceivers support OOK/ASK modulation, I haven’t t really found anyone who successfully used them to control power plugs. I’ll admit that the lack of security and one-way communication makes the old 433 Mhz systems feel somewhat dated - and probably not interesting enough for developers to sink their teeth into on behalf of my needs :wink: But the system works, it’s cheap, and available almost everywhere.

Back to the problem, implement Rx with crappy SRR without getting stuck in an endless receive-loop! Since I cant do anything about the inherent flaws, the only solution that I could think of is to add a Slave MCU with the sole purpose of decode signals (and listen to noise). When a signal is received from my remote, it gets decoded and parsed to the Master via serial. Some functions to split, convert and match the data and Voila! I can now use both my remote and Blynk-app to control my plugs :smiley:

This approach will hopefully keep the Blynk-functions running smoothly! I have some very basic (ugly) code running for a couple of hours now and it seems to work. I’ll upload the code when I’ve done some more testing. At the moment I’m using Arduino Uno’s both as Slave and Master, but if possible i’ll change the Slave to an ATTiny85 (need to read some documentation).

Back to the… future?! Texas Instruments CC1101 (LoRa) transceiver has a fair amount of interesting libs on Github with functions to deal with OOK/ASK communication. Worth looking in to!

Feedback, suggestions, tips and tricks are most welcome!

(This post is perhaps better suited in a different category? Be gentle)

I am ALWAYS gentle :innocent:

Actually this sounds interesting, and RF 433 MHz was the general topic of your OP, so add to this as you feel necessary, but also feel free to create a new “Projects made with Blynk” topic with lots of details if you chose.

As someone pointed out elsewhere: “The art of getting good answers lies in asking good questions!” :nerd_face:

The most important goal of my project was scheduling and some form of online interface. Blynk, and @Costas code, made that (surprisingly) easy even with limited programming experience. Interfacing a receiver on a second MCU makes it a challenge! :grin:

I’ll probably end up with a bunch of non Blynk related Q’s, but that’s what books are for :slight_smile: Hopefully I can make post in the “Projects made with Blynk.” section soon - unless you start a “Projects I’m working on” subsection first hehe.

Not sure if this is what you are refering too… but have you looked at this library for sharing data between Arduinos? Not sure how well it works for ESP.

I haven’t looked into specific libraries yet, but that looked interesting. For the moment I’m just using the built-in UART to get a better understanding of how I can parse and make use of the data. The data sent over to the master looks something like this 1912830,1,15,0,-1, and the day before yesterday I didn’t know what heck strtok, atol, atoi, atof was. So you see where the real challenge lays! :upside_down_face:

I quickly found out that when the master sends a command, the slave pics it up and sends it back to the master to be resent and… doh Need to address that problem first, then figure out if I should use UART, I2C or SPI.

No sure if we are still dealing with the original OP issue, but I switched your topic back to “Need help…” for the time being :wink:

Hello friends, I have received your reply.

I have sent an e-mail to Nodemcu’s manufacturer’s engineer (I purchased the company’s product)
The advice given by their engineers is
Use dual power solutions, or power isolation.
I chose the power isolation scheme.
Because it is the fastest and most effective.
Also, please note that I purchased this 433m module does not have the serial transceiver function, it only 4 logic control.
If you use the 433m module with serial transceiver function, please pay more attention to the interference from the circuit.

This sounds far too complicated to me!
If the power plug that you’re trying to control is within range of Wi-Fi then the simplest solution is to use an ESP/NodeMCU device to talk directly to Blynk and control the relays - or simply use a Sonoff S20 if you don’t want to build your own power switch with built-in ESP8266.

If the power plug isn’t within Wi-Fi range then use a powerline Wi-Fi adaptor to give you Wif-Fi where you need it.

If you then need the ability to use a 433Mhz handheld transmitter as well as the Blynk app to turn the power sockets on an off then have another ESP or Arduino+Ethernet device in a convenient location with a 433Mhz receiver attached to it. When you receive a signal from the 433Mhz handheld transmitter the ESP tells the Blynk cloud server to turn the power sockets on or off.

Pete.

I understand that my solution seems complicated, but there are some things to consider. The thread is getting long, so to summarize what I want to achieve with my remote controlled plugs:

  1. Scheduling.
  2. An online interface.
  3. Co-operation with physical remotes.

But there is a snag - It has to work even if it gets disconnected from internet!

Therefore, I cannot use the receiver as a bridge that only sends updates through Blynk. Same goes for Eventor and scheduled tasks. I do appreciate your feedback and took a closer look at what Sonoff has to offer. Lo and behold, they have a neat little product called “Sonoff RF Bridge 433”! :smiley: It requires internet, are probably not compatible with my plugs, and the app doesn’t change status set by remote controllers. So not quite right for me. But the first commercial product I’ve seen that has those features (and not costing $300).

The schematic for the device can be found on ITEAD’s webpage and that is interesting. Their solution [for my problem] is to use a C8051 MCU that handles all Rx/Tx for 433Mhz (presumably, it’s wired like that) and the ESP do all the other stuff.

[Back to me] So, in order to cope with both transmitter and receiver, using two MCU’s seems like a good idea!

Okay, would it be acceptable to have devices connected to a Wi-Fi network that remains up and running when the internet connection goes down?
If so, you could use Sonoff/ESP8266/NodeMCU devices connected to the Wi-Fi network, then use MQTT to communicate between the devices.

It’s possible to do a serverless MQTT implementation, but I use a Raspberry PI to run Mosquitto and Node-Red. Mosquitto is the MQTT broker and Node-Red is a sort of drag and drop development environment that can process MQTT messages and can also communicate with Blynk (if the internet is up of course).
Node-Red gives a basic user interface that can be accessed via a web page on the local network and gives the ability to control your devices if the internet is down.
Setting-up the RPi server is easy using Peter Scargill’s (@scargill) script and I’ve been running mine for over a year without the need for any manual intervention.

Pete.

I use to work with i2c between 2 nano. I’m happy with this method. Easy and reliable.

I might have been a little bit vague about my needs… And you can - apparently not - read my mind hehe :wink: Even worse is when people don’t “practice what they preach”:

My bad!

Anyhow… The online interface doesn’t need to be up 24/7, the important thing is that scheduling works independently of internet. If I get some connection issues while at home I can simply use the remote or even the buttons on the plugs themselves. But with Murphy’s law and all that, any connection issues will probably happens when I’m not at home and during the schedules grace period.

My current setup works (as regarding to 1 & 2), it just needs some minor code changes and cleanup. If I can get the remotes to co-op it’s just a bonus and not “mission critical”. But to keep the main loop() as clean as possible (with current hardware) and keep Blynk happy, a second MCU is my only real option. And that’s what I’m fiddling with now!

I didn’t know that a serverless MQTT was possible and I’ll keep that in mind for upcoming projects! :+1: But I’ll stick to my dumb, old school switches for the moment :slight_smile:

/D

One solution is to have a Local Server… thus while the link is dependent on the local network, it is not dependent on the internet.

That thought has crossed my mind a thousand times or so :smiley: If I had chosen to use a local server, basically all my goals could have been reached without much effort I guess. I could even reuse my Tellstick USB transmitter and one of many interfaces found on eg. GitHub. But that still doesn’t solve the problem with both receiving and transmitting.

So why can’t I stop wailing about this and take the easy way out?

Telldus is popular company in Sweden that sells home automation products (like my now defunct Tellstick). They have a 433Mhz gateway capable of both rx and tx, scheduling, events, app interface etc - with a retail price of $135!

Don’t get me wrong, I really do appreciate that people takes interest and give me tips and suggestions for (other) possible solutions. But wouldn’t it be GREAT to drum up a $8 solution with some Blynk energy for the same basic functions?

That’s why I’m wailing :rofl:

Could you explain in more detail the receiving part of your project. I can understand transmitting an RF signal to your sockets but not the receiving,

And you just want to use Arduino’s, right?

@Costas - Presumably he wants to replicate the 433Mhz hub - receiving signals from various transmitters and applying some logic before transmitting a signal to one or more devices that have a receiver built in to them?

@distans - I also have a requirement for a 433Mhz transmitter/receiver capability for my home automation project at our holiday home in Spain. We have what the Spanish call “Toldos”, which are canopies on the outside of the windows that can be used to provide shade when it’s sunny. These use a tubular motor to operate them and have a 433Mhz receiver built-in. Each Toldo has its own handheld transmitter and we have three of these in total.
I want to be able to use Blynk and/or a Nextion touch screen to control these canopies. I also want to be able automatically to retract the blinds if it gets too windy, or if it starts to rain, to help preserve the life of the material that they’re made of. At the same time, I want the original handheld controllers to be able to use, as they are convenient in some situations.

In addition, I have some outside lights that are operated by PIR sensors, but I’ve added a Sonoff to the circuit to be able to override the PIRs and put the lights on for 1 hour by using a button in Blynk. I’d like to add a handheld 433Mhz fob (garage door opener) to this setup so that pushing one button on the fob will put the lights on for an hour, pressing the other button will cancel the timer and revert to standard PIR operation. This will allow visitors to control the lights without them having to install Blynk on their phone.

I could use a variety of other technologies for the outside light issue, but I’m stuck with 433Mhz for the canopies, so need to get a 433Mhz transmission working at the very least. Ideally I’d also want to be able to know when the handheld transmitters have been used to extend one or more of the canopies, so that I know if they need to be retracted. (They have built-in limit switches so sending a retract command won’t do any damage, but I’d like to understand their position in more detail if I can). So a 433Mhz receiver that can pick-up the commands from the handheld controllers would also be needed.

I’ve ordered a variety of 433Mhz transmitters and receivers from AliExpress and eBay, and these should have arrived by the time I get out to Spain again in early November. There’s a couple of other threads on Hera and other forums about poor range and interference issues with the regular cheap 433Mhz tx/rx kit that most of the Chinese suppliers are selling, so I want to have a variety of hardware to choose from when it comes to trying to get my system working.

For my solution I’ll be using MQTT and Node-Red as I want to combine data from multiple sources (windspeed, ambient light and rainfall sensors on the roof, temperature sensors in various rooms of the house, input from the Nextion touch screen etc) with data from 433Mhz receiver. I also want to use a timer finction to retract the canopies at sunset, and as I already use Peter Scargill’s ‘big timer’ in Node-Red for other home automation tasks around the house I’ll use that for this as well.
I’ll let you know how how I get on, but I’d also appreciate knowing more about what you manage to achieve with your experimentation - especially with regard to the range and reliability of the 433Mhz kit you’re using.

Pete.

@PeteKnight is the place in Spain a house or apartment and what would you say is the distance from a dead centre of the property to the Toldos (with the distance being the same for all 3 Toldos)?

What is the type and thickness of walls and the average number of walls, again from the centre of the property to the outside of the property.

Hi @Costas it’s a house, but all of the Toldos are on the upper floor, which is our living area. Two are in the living room and less than 4m apart with clear air between. The 3rd is in a bedroom which is about 8m from the nearest place in the living room where I could position a 433Mhz transmitter. Walls are brick, with some reinforced concrete pillars dotted around for good measure.

The downstairs seating area, where people would sit to operate the outside lights is about 5m below the living room area and directly below one of the Toldos.

I get excellent Wi-Fi reception through the house and outdoor area as I have a couple of wireless access points in addition to my router, so I guess I could have 433Mhz transmitters and receivers dotted around the house by linking them to ESP8266s and wiring them into the mains supplly, but I’d prefer not to do that unless I have to. I suppose I might also run into issues with ineterference between the devices if I’m not careaful.

Any thoughts on how successful this setup would be and any reccomendations on 433Mhz hardware?

Pete.

@PeteKnight I think this is what I would do but i’m a cheapskate :slight_smile:

3 cheap “WeMos” type boards and the sub $1 RF transmitters, WITH aerials.
A Pi Zero W local server.
Project also running on Blynk cloud server.
Leave a cheap $40 Android in the property for any guests to use.
Do away with the RF handsets.
The local server can send you messages regarding the status of each Toldos.

1 Like