My Project:
First of all a short summary of what a plan to do with Blynk:
I want to build many small Low Power Sensor Nodes and place them in ever room of my flat. To be as energy efficient as possible for long runtime a choose an Arduino Pro mini with an NRF24l01+ for this task. Theses Sensor nodes run my very own code. No blynk code running on them.
I want to collect the data from the sensor nodes on a raspberry pi zero w running a local blynk server. I already made it work with an Arduino with an NRF24 connected via USB using the blynk-ser.sh script as well as connecting the Arduino via UART to the raspberry again using blynk-ser.sh script.
But i would like to futher reduce the hardware and the power consumption by removing the arduino and connect the NRF24l01+ directly to the raspberry pi zero w.
What works so far:
By now I am able to run an test programm written in c++ to receive data with the NRF24 (not including any blynk related code or libraries).
I am also able to run the blynk programm (main.cpp) included in the blynk-library for linux to connect the blynk client to the local server.
My Problem:
I am unable to compile the programm (main.cpp) as soon as I try to add Code to create an object of the class RF24. The added lines to the main.cpp and the error of the compiler looks as follows:
#include “/home/pi/RF24/RPi/RF24/RF24.h”
// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
main.o: In function _GLOBAL__sub_I_Blynk': main.cpp:(.text.startup+0x994): undefined reference to
RF24::RF24(unsigned char, unsigned char, unsigned int)’
collect2: error: ld returned 1 exit status
comments:
I know about node.js and I tried to make the NRF24 run with the node-nrf library but I was unable to. Since I nerver used javascript I turned back to C++ where I am more experienced.
I am quite new to linux and I never dealt with makefile. (It seem to me that my problem is related to the setup of the makefile)
Can anyone help me with my problem, please?
1 Like
you’ll have to firure it out… you need to “link” the main application with nrf24 library.
thanks for your quick reply!
If possible, can you or someone else explain in more detail where to start searching for the problem.
Is my guess with the makefile right?
I was expecting that including the header file (RF24.h) like shown in the first post would do the job of linking.
I managed to merge the makefiles, The program is compiling and running!
My modified makefile looks like this:
#
# To build on RaspberryPi:
# 1. Install WiringPi: http://wiringpi.com/download-and-install/
# 2. Run:
# make target=raspberry
# sudo blynk --token=YourAuthToken
#
CC ?= gcc
CXX ?= g++
CXXFLAGS += -I ../src/ -I ./ -DLINUX -I../ -lrf24-bcm
LDFLAGS += -lrt -lpthread
ifeq ($(build),debug)
CXXFLAGS += -c -g2 -O0 \
-Wall -Weffc++ \
-Wextra -Wcast-align \
-Wchar-subscripts -Wcomment -Wconversion \
-Wdisabled-optimization \
-Wfloat-equal -Wformat -Wformat=2 \
-Wformat-nonliteral -Wformat-security \
-Wformat-y2k \
-Wimplicit -Wimport -Winit-self -Winline \
-Winvalid-pch \
-Wunsafe-loop-optimizations -Wlong-long -Wmissing-braces \
-Wmissing-field-initializers -Wmissing-format-attribute \
-Wmissing-include-dirs -Wmissing-noreturn \
-Wpacked -Wparentheses -Wpointer-arith \
-Wredundant-decls -Wreturn-type \
-Wsequence-point -Wshadow -Wsign-compare -Wstack-protector \
-Wstrict-aliasing -Wstrict-aliasing=2 -Wswitch -Wswitch-default \
-Wswitch-enum -Wtrigraphs -Wuninitialized \
-Wunknown-pragmas -Wunreachable-code -Wunused \
-Wunused-function -Wunused-label \
-Wunused-value -Wunused-variable \
-Wvolatile-register-var -Wwrite-strings
# Disable some warnings
CXXFLAGS += -Wno-variadic-macros -Wno-unused-parameter -Wno-vla
# Uncomment this to get pedantic warnings:
#CXXFLAGS += -pedantic -Wvariadic-macros -Wunused-parameter -Waggregate-return -Wcast-qual -Wpadded
else
CXXFLAGS += -c -O3 -w
LDFLAGS += -s
endif
ifeq ($(target),raspberry)
CXXFLAGS += -DRASPBERRY
LDFLAGS += -lwiringPi
endif
SOURCES= main.cpp \
BlynkDebug.cpp \
../src/utility/BlynkHandlers.cpp \
../src/utility/BlynkTimer.cpp \
/home/pi/RF24/RPi/RF24/RF24.cpp
SOURCES2=/home/pi/RF24/RPi/RF24/bcm2835.c
OBJECTS=$(SOURCES:.cpp=.o)
OBJECTS+=$(SOURCES2:.c=.o)
EXECUTABLE= blynk
all: $(SOURCES) $(SOURCES2) $(EXECUTABLE)
clean:
-rm $(OBJECTS) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CXX) $(OBJECTS) $(LDFLAGS) -o $@
.cpp.o:
$(CXX) $(CXXFLAGS) $< -o $@
The lines I edited are:
CXXFLAGS += -I …/src/ -I ./ -DLINUX -I…/ -lrf24-bcm
/home/pi/RF24/RPi/RF24/RF24.cpp
SOURCES2=/home/pi/RF24/RPi/RF24/bcm2835.c
OBJECTS+=$(SOURCES2:.c=.o)
all: $(SOURCES) $(SOURCES2) $(EXECUTABLE)
2 Likes
If you would like to save your program in a folder diffrent to the “/home/pi/blynk-library/linux” folder you have to change the following line of the makefile to:
CXXFLAGS += -I /home/pi/blynk-liibrary/src/ -I ./ -DLINUX -I…/ -lrf24-bcm
SOURCES= main.cpp \
/home/pi/blynk-library/linux/BlynkDebug.cpp \
/home/pi/blynk-library/src/utility/BlynkHandlers.cpp \
/home/pi/blynk-library/src/utility/BlynkTimer.cpp \
you also have to change the path of the included libraries in the main.cpp:
#include </home/pi/blynk-library/linux/BlynkApiWiring.h>
#include </home/pi/blynk-library/linux/BlynkSocket.h>
#include </home/pi/blynk-library/linux/BlynkOptionsParser.h>
If you don’t want to always enter the auth token and the server address when executing your programm you can modify the main function of the main.cpp like this:
int main(int argc, char* argv[])
{
const char *auth = {"your auth token"};
const char *serv = {"127.0.0.1"};
uint16_t port = 8442;
Blynk.begin(auth, serv, port);
setup();
while(true) {
loop();
}
return 0;
}
1 Like