Push data (value to V7)

Hi everybody
Here is my sketch. All the ’ blink_writes’ are doing fine.
The problem is reading data, coming from a RF receiver. I would like to see a code on V7 (see Blynk_read(v7)
I tried receiving the data without blink and that works fine, with blink no value on V7. I the app I switched value on’ push’
Am I doing something wrong ???

#define BLYNK_PRINT Serial// Comment this out to disable prints and save space
#include <OneWire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <NewRemoteTransmitter.h>//nodig voor KAKU
#include <RCSwitch.h>//nodig voor Promax
#include <SimpleTimer.h>
int waarde=0;
int ledstatus=0;
int value;
char auth[] = “xxx”;// Je Blynk auth code.
#define W5100_CS 10
#define SDCARD_CS 4

SimpleTimer timer;

NewRemoteTransmitter transmitter(3256158, 10, 255 ,1);

RCSwitch mySwitch = RCSwitch();
void bewegingStatus(void);

void setup()
{
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH);

Serial.begin(9600);
Blynk.begin(auth);
pinMode(9,OUTPUT);// +spanning voor de RF transmitter
pinMode(7,OUTPUT);
mySwitch.enableTransmit(10);
mySwitch.enableReceive(0);//dit is D2

}

BLYNK_WRITE(V1)
{
if (param.asInt()){
digitalWrite(9,HIGH);
mySwitch.send(1381717,24);
digitalWrite(9,LOW);
}
else {
digitalWrite(9,HIGH);
mySwitch.send(1381716,24);
digitalWrite(9,LOW);
}
}
BLYNK_WRITE(V2)
{
if (param.asInt()){
digitalWrite(9,HIGH);
mySwitch.send(1394007,24);
digitalWrite(9,LOW);

}
else {
digitalWrite(9,HIGH);
mySwitch.send(1394004,24);
digitalWrite(9,LOW);

}
}
BLYNK_WRITE(V3)
{
if (param.asInt()){
digitalWrite(9,HIGH);
mySwitch.send(1397077,24);
digitalWrite(9,LOW);
}
else {
digitalWrite(9,HIGH);
mySwitch.send(1397076,24);
digitalWrite(9,LOW);
}
}
BLYNK_WRITE(V4)
{
if (param.asInt()){
digitalWrite(9,HIGH);
mySwitch.send(1397845,24);
digitalWrite(9,LOW);
}
else {
digitalWrite(9,HIGH);
mySwitch.send(1397844,24);
digitalWrite(9,LOW);
}
}

BLYNK_WRITE(V6)//KAKU
{
if (param.asInt()){
digitalWrite(9,HIGH);
transmitter.sendUnit(1,true);
digitalWrite(9,LOW);
}
else {
digitalWrite(9,HIGH);
transmitter.sendUnit(1,false);
digitalWrite(9,LOW);
}

}

BLYNK_READ(V7)
{
if (mySwitch.available()){
int value=mySwitch.getReceivedValue();
Serial.println(value);}
{
Blynk.virtualWrite(V7,value);
}
}

void loop()
{
Blynk.run();

}

Please use formatting. Impossible to read your code.

Sorry
Here a short version:
(trying to receive a 433mhz RF signal and plot it in the app as a value.
What am I doing wrong ???

#define BLYNK_PRINT Serial// Comment this out to disable prints and save space
#include <OneWire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>`Preformatted text`
#include <RCSwitch.h>//nodig voor Promax
int value=0;
char auth[] = "xxxxx";// Je Blynk auth code.
 #define W5100_CS 10
 #define SDCARD_CS 4
 


RCSwitch mySwitch = RCSwitch();
 
 
void setup()
{
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH);
  
  Serial.begin(9600);
  Blynk.begin(auth);

mySwitch.enableReceive(0);//   This is D2
  }


BLYNK_READ(V5)
{
if (mySwitch.available()){
int value=mySwitch.getReceivedValue();
Serial.println(value);}{
Bynk.virtualwrite(V5,value);}


void loop()
{
 Blynk.run();
}

@Eeuwe please try submitting your sketch to the forum again or edit your last post.

3 backticks cpp
paste code on next line
3 backticks on a new line after the last line of your sketch

I hope you van read it now ?!

@newuser and @Eeuwe yes we can read it now but stop posting as 2 different users and creating multiple threads.
The other thread will be ignored as not only is it a duplicate of this one but the code is unreadable.

I have your sketch running here.

Just checking out a few issues and then I will post further details/

What widget are you using for V5?

Hi
I’m using ‘value display’ in the app
With best wishes
Eeuwe

@Eeuwe this is our ESP8266 version which includes the code in loop(). Generally this is not a good idea for Blynk sketches but it’s ok for a simple sketch like this.

//RCSwitchDecimal.ino 29 Nov 2016 by Costas
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <RCSwitch.h>

char auth[] = "xx";
char ssid[] = "xx";
char pass[] = "xx";
char server[] = "blynk-cloud.com";

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(115200);
  //mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is Arduino pin #2
  mySwitch.enableReceive(12);   // Receiver on GPIO12 that is WeMos pin D6 MOSI
  Blynk.begin(auth, ssid, pass, server);
  unsigned long maxMillis = millis() + 8000;
  while ((Blynk.connect() == false) && ( millis() <= maxMillis)) {
  }
}

void loop() {
  Blynk.run();
  if (mySwitch.available()) { 
    //int value = mySwitch.getReceivedValue();  // int is not big enough on an Arduino
    unsigned long value = mySwitch.getReceivedValue();
    Serial.println(value);
    Blynk.virtualWrite(V5, value);  // V5 is large Value Display widget
    mySwitch.resetAvailable();
  }
}

Modify for your hardware.

Dear Costas
Thank you very much, it looks like its working !!
I though that Blynk.virtualWrite should not be placed in the void loop()…
Isn’t that so ?

Regards
Eeuwe

Indeed my Blynk_write functions (not in the void loop() ) are not very stable anymore…

It shouldn’t really but as it’s only triggered when the RF signal is sent it is not trying to send at a 1000 times a second.

If your sketch gets more detailed you should perhaps look at attachInterrupt for the RF receiver etc.

With the sketch as it is you will find that the RF signal is not always picked up as it will be busy doing other things but as it is the receiver rather than the transmitter it shouldn’t be a problem.

Thanks again
I will continue with my project by trial and error !!!
Didn’t mention before but Blynk is really great !!!

Post your full sketch but ensure it is formatted correctly.

With the if statement in loop() it shouldn’t be doing anything for 99% of the time so it shouldn’t really interfere with the rest of the sketch.

Here's my complete sketch with yours as basis:

//RCSwitchDecimal.ino 29 Nov 2016 by Costas
//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <RCSwitch.h>
#include<BlynkSimpleEthernet.h>

char auth[] = "xxxxxxxxx";
char server[] = "blynk-cloud.com";
 #define W5100_CS 10
 #define SDCARD_CS 4
RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(115200);
  pinMode(9,OUTPUT);
  mySwitch.enableTransmit(10);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is Arduino pin #2
  //mySwitch.enableReceive(12);   // Receiver on GPIO12 that is WeMos pin D6 MOSI
  Blynk.begin(auth, server);
  unsigned long maxMillis = millis() + 8000;
  while ((Blynk.connect() == false) && ( millis() <= maxMillis)) {
  }
}
BLYNK_WRITE(V1)
{
if (param.asInt()){
digitalWrite(9,HIGH);
mySwitch.send(1381717,24);
digitalWrite(9,LOW);
    }
else {
digitalWrite(9,HIGH);
mySwitch.send(1381716,24);
digitalWrite(9,LOW);
}
}
BLYNK_WRITE(V2)
{
if (param.asInt()){
digitalWrite(9,HIGH);
 mySwitch.send(1394007,24);
digitalWrite(9,LOW);
 
} 
else {
digitalWrite(9,HIGH);
  mySwitch.send(1394004,24);
digitalWrite(9,LOW);
 
}
}
BLYNK_WRITE(V3)
{
if (param.asInt()){
digitalWrite(9,HIGH);
 mySwitch.send(1397077,24);
digitalWrite(9,LOW);
} 
else {
digitalWrite(9,HIGH);
 mySwitch.send(1397076,24);
digitalWrite(9,LOW);
}
}
BLYNK_WRITE(V4)
{
    if (param.asInt()){
digitalWrite(9,HIGH);
mySwitch.send(1397845,24);
digitalWrite(9,LOW);
} 
else {
digitalWrite(9,HIGH);
mySwitch.send(1397844,24);
digitalWrite(9,LOW);
}
}
void loop() {
  Blynk.run();
  if (mySwitch.available()) { 
    //int value = mySwitch.getReceivedValue();  // int is not big enough on an Arduino
    unsigned long value = mySwitch.getReceivedValue();
    Serial.println(value);
    Blynk.virtualWrite(V5, value);  // V5 is large Value Display widget
    mySwitch.resetAvailable();
  }
}

@newuser I suspect your problems are related to the W5100 and SD card rather than the RCSwitch code.

You could try commenting out the lines in loop() but I wouldn’t expect that to improve the situation.

For an ESP (WeMos) the lines of code I provided runs trouble free in a project with 3 full tabs of widgets.

There are quite a few W5100 threads on this site and one for example for you to perhaps take a look at is this one Arduino + w5100 ethernet shield error

I notice you have transmitter pin set as 10, isn’t that used by the W5100 as per the W5100 spec?