Using C++ on a Raspberry Pi with Blynk

Thank you !

I seem to be having the same issues … running 0.4.8

getting flood errors . currently using the RP3

How can flood errors be the same issues? you’ll have to search how to fight flood errors now.

Just because I’ve followed the instructions Costas and it hasn’t worked. I’m having a similar to the issue werewolflabs is having. Which is what this thread is about “getting started with C++ implementation”

I would be nice to have a Docs page support which have a set of instructions (checked and verified) on how to get C++ running on a standard Rpi setup and not have to resort to a forum post to find all this info.

@esa.attia - Yes you’re right! It would be nice - and we are ready to accept your contributions and help spreading them among the community! :wink:
If you’re working on a commercial project - you can get support from our highly qualified developers @ Blynk for Business.
Cheers.

1 Like

3 posts were merged into an existing topic: Push button notification on Raspberry Pi 3

Hi all,

I tried to compile Blynk library 4.10 on my raspberry pi 3.
But unfortunately compilation is not working…

I have an error on “BlynkOnDisconnected” function that has not been found in sources file.

Does anyone can help Me?
What I’m doing wrong?

Is it possible to compile using CygWin?
Is it mandatory install WiringPi?

Thanks a lot

Hello, Did someone tried to run RTC from examples on Raspberry Pi Zero? For push data it works (uptime in sec % min), but when I try for RTC I receive this error:
In file included from main.cpp:13:0:
…/src/WidgetRTC.h:15:6: error: #error WidgetRTC is not available on this platform!
#error WidgetRTC is not available on this platform!

Can you help?

You would need to link the required libraries etc that’s why I used millis() in the example provided.

can you be more specific what I need to do (one example); I’m using Raspbian on RI Zero and a local server; Blynk libraries were installed yesterday. Here are some other error received while compiling:
In file included from …/src/WidgetRTC.h:18:0,
from main.cpp:13:
…/src/Blynk/BlynkWidgetBase.h: In member function ‘void BlynkWidgetBase::setLabel(Args …)’:
…/src/Blynk/BlynkWidgetBase.h:27:9: error: ‘Blynk’ was not declared in this scope
Blynk.setProperty(mPin, “label”, args…);
^~~~~
…/src/Blynk/BlynkWidgetBase.h: In member function ‘void BlynkWidgetBase::setColor(Args …)’:
…/src/Blynk/BlynkWidgetBase.h:32:9: error: ‘Blynk’ was not declared in this scope
Blynk.setProperty(mPin, “color”, args…);
^~~~~
In file included from main.cpp:13:0:
…/src/WidgetRTC.h: In static member function ‘static time_t WidgetRTC::requestTimeSync()’:
…/src/WidgetRTC.h:37:5: error: ‘Blynk’ was not declared in this scope
Blynk.sendInternal(“rtc”, “sync”);
^~~~~
main.cpp: In function ‘void clockDisplay()’:
main.cpp:29:3: error: ‘String’ was not declared in this scope
String currentTime = String(hour()) + “:” + minute() + “:” + second();
^~~~~~
main.cpp:30:10: error: expected ‘;’ before ‘currentDate’
String currentDate = String(day()) + " " + month() + " " + year();

I’m not able to run DHT too; is there a tutorial to show how to setup libraries to be able to execute C++ programs? I’m trying to run programs from examples:
https://examples.blynk.cc/?board=Raspberry%20Pi&shield=System%20default&example=More%2FDHT11

All the examples in the Sketch Builder are for Arduino, Arduino like and ESP based MCUs

FYI, RPi can work with Blynk using WiringPi (C++) or Node.js, but as stated in the Help Center, anything beyond the basic direct pin control with options require much more experience…

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/raspberry-pi/nodejs-vs-c-library

Use Blynk with C++
If you want just to toggle a pin, it will simply work out-of-the-box.
But if you want to add more functionality, it will require some Linux, threading, sockets knowledge, modifying Makefile, etc.
So, C++ is generally for advanced developers.

In the examples pages there are raspberry pi programs to be build

I know… I have mentioned that in the past to the Developers :wink: … and it has gotten better.

In theory most can be used with the WiringPi method, as it is C++ based… but not all as drop-in solutions, as many 3rd party libraries may not actually be supported on the RPi or WiringPi, syntax for workarounds may be different, and well, an RPi is not an Arduino… period.

Personally I started with WiringPi and quickly moved toward Node.js… I found more references available with Google… but still a lot of trial and error discovering the correct way to use Blynk with it.

ok…thx…I have to move back to ESP

Don’t give up entirely… there are a few others here who have some WiringPi experience.

And search here for NodeJS stuff… there are a few small examples… plus what is available on the Help Center document I linked to. I have been actively learning to control many things on my RPi3 with Blynk and quite like the power of the RPi :smiley:

basic functionality for buttons works ok, but I want to try simple things like RTC or DHT 22 - and not able to solve it. Basically I want to be able to connect sensors to RPI (movement, Temp, Light, distance, magnetic etc…RPI is much better due to flexibility to update the program, connectivity etc. I have elimitated a lot of errors during the build, but still errors I cannot fix, so I cannot enjoy RTC or DHT on my RPI Zero. Switching to NodeJS…it’s like starting with the left foot…

Hello @Costas first thank you for the post.

Do you have any C++ example that fits in this case using the serial.read?

Example: I want to read serial information from Arduino which is connected to the Raspberry USB port and put on Blynk virtual pin?

@Clucas this is what I always recommend for MCU to MCU interfacing https://forum.arduino.cc/index.php?topic=396450.0

Hello @Costas, thank you but this is more related to interface Arduino <-> Arduino, this interface I am able to do. But how could I modify the example below to receive the serial data from Arduino on the Raspberry USB port?

The port in raspberry is /dev/ttyACM0 which somehow needs to be declared?!

=/

// Blynk "gp" numbers are BCM numbers, so gp17 is physical pin 11 
// #define BLYNK_DEBUG
#define BLYNK_PRINT stdout
#ifdef RASPBERRY
 #include <BlynkApiWiringPi.h>
#else
 #include <BlynkApiLinux.h>
#endif
#include <BlynkSocket.h>
#include <BlynkOptionsParser.h>

static BlynkTransportSocket _blynkTransport;
BlynkSocket Blynk(_blynkTransport);

#include <BlynkWidgets.h>

unsigned int uptime;      		// 1 second intervals
unsigned int pinStatus;   		// status of BCM 17
unsigned int lastpinStatus = 0; // to toggle

void myTimerEvent()       		// button widget on V0 or direct access gp17 button
{
  uptime = (millis() / 1000);
  Blynk.virtualWrite(V1, uptime);
  pinStatus = digitalRead(17);
  if(pinStatus != lastpinStatus){
	lastpinStatus = pinStatus;
	printf("GP17 pin status: %i\n", pinStatus);
	if(pinStatus == 1){    // this is to synchronise V1 button if gp17 button is pressed
		Blynk.virtualWrite(V0, 1);
	}
	else{
		Blynk.virtualWrite(V0, 0);
	}
  }
}

void setup()
{
  //nothing to go here yet
}

BLYNK_WRITE(V0)  // button set at PUSH frequency
{
  if(param[0] == 1){
	printf("V1 turned device ON\n");
	digitalWrite (17, HIGH) ;  
  }
  else{
	printf("V1 turned device OFF\n");
	digitalWrite (17, LOW) ;
  }
}

void loop()
{
  Blynk.run();
  if(millis() >= uptime + 1){  // 1 second intervals
	myTimerEvent();
  }
}

int main(int argc, char* argv[])
{
    const char *auth, *serv;
    uint16_t port;
    parse_options(argc, argv, auth, serv, port);
    Blynk.begin(auth, serv, port);
    while(true) {
		loop();
    }
    return 0;
}

Using NodeJS I am able to receive the data from Arduino, but, I am unable to allocate them on the Virtual Pins (So I believe its easier to try to make it work with C++ above):

const SerialPort = require(‘serialport’);
const port = new SerialPort(’/dev/ttyACM0’, () => {
console.log(‘Port Opened’);
});
const parsers = SerialPort.parsers;

const parser = new parsers.Readline({
delimiter: ‘\n’

});

port.pipe(parser);

parser.on(‘data’, console.log);