Skip to content

Commit

Permalink
enable building IRQ-based examples (#36)
Browse files Browse the repository at this point in the history
IRQ support is now technically available in all RF24 drivers. This updates the examples' build config accordingly.

* trigger Linux CI on changes to examples/**CMakeLists.txt
* remove .vscode folder
* update python examples for python3
  • Loading branch information
2bndy5 authored Jun 17, 2024
1 parent 635e520 commit 21c5165
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- "CMakeLists.txt"
- "cmake/**"
- "examples/**.cpp"
- "examples/**CMakeLists.txt"
- "!**Makefile" # old build system is not tested in this workflow
- ".github/workflows/build_linux.yml"
push:
Expand All @@ -19,6 +20,7 @@ on:
- "CMakeLists.txt"
- "cmake/**"
- "examples/**.cpp"
- "examples/**CMakeLists.txt"
- "!**Makefile" # old build system is not tested in this workflow
- ".github/workflows/build_linux.yml"
release:
Expand Down
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

28 changes: 7 additions & 21 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ elseif("${RF24_DRIVER}" STREQUAL "wiringPi")
else()
message(FATAL "Lib ${RF24_DRIVER} not found.")
endif()
elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" AND NOT DEFINED RF24_NO_INTERRUPT)
if(NOT "${RF24_DRIVER}" STREQUAL "pigpio")
message(STATUS "linking to ${LibPIGPIO} for interrupt support")
else()
elseif(NOT "${RF24_DRIVER}" STREQUAL "pigpio")
if(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND")
message(STATUS "linking to ${LibPIGPIO}")
list(APPEND linked_libs ${LibPIGPIO})
else()
message(FATAL "lib ${RF24_DRIVER} not found.")
endif()
list(APPEND linked_libs ${LibPIGPIO})
else()
message(STATUS "Disabling IRQ pin support")
endif()

set(example RF24GatewayNode)
Expand All @@ -63,24 +61,12 @@ add_executable(${example} ${example}.cpp)
target_link_libraries(${example} PUBLIC
${linked_libs}
)
if("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" OR DEFINED RF24_NO_INTERRUPT)
target_compile_definitions(${example} PUBLIC RF24_NO_INTERRUPT)
endif()

if("${RF24_DRIVER}" STREQUAL "MRAA" OR "${RF24_DRIVER}" STREQUAL "wiringPi")
message(STATUS "skipping gwNodeInt example because it is incompatible with selected driver")
elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" AND NOT DEFINED RF24_NO_INTERRUPT)
add_subdirectory(gwNodeInt)
endif()

add_subdirectory(gwNodeInt)
add_subdirectory(addons/Sniffer)

include(../cmake/enableNcursesExample.cmake)
if(BUILD_NCURSES_EXAMPLE)
add_subdirectory(ncurses)
if("${RF24_DRIVER}" STREQUAL "MRAA" OR "${RF24_DRIVER}" STREQUAL "wiringPi")
message(STATUS "skipping ncursesInt example because it is incompatible with selected driver")
elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" AND NOT DEFINED RF24_NO_INTERRUPT)
add_subdirectory(ncursesInt)
endif()
add_subdirectory(ncursesInt)
endif()
3 changes: 0 additions & 3 deletions examples/addons/Sniffer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ add_executable(${example} ${example}.cpp)
target_link_libraries(${example} PUBLIC
${linked_libs}
)
if("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" OR DEFINED RF24_NO_INTERRUPT)
target_compile_definitions(${example} PUBLIC RF24_NO_INTERRUPT)
endif()
11 changes: 3 additions & 8 deletions examples/addons/mqttLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
RF24NetworkFrame frame = RF24NetworkFrame(header, buf, size);
gw.sendUDP(mesh.getNodeID(header.from_node), frame);
"""
import paho.mqtt.client as mqtt
import socket

try: #python 2 to 3 hack
unicode("") # all strings are unicode in python3
except NameError:
unicode = str # does the same thing as python2's builtin unicode()
import socket
import paho.mqtt.client as mqtt

### Setup the MQTT host IP & topic to publish to
mqttHost = "10.10.2.2"
Expand All @@ -29,7 +25,6 @@
sock.bind(server_address)

while True:

data, address = sock.recvfrom(2048)

print("received {} bytes from {}".format(len(data), address))
Expand All @@ -40,6 +35,6 @@
# TODO: Sort, Display and Analyze the data
mqttc = mqtt.Client()
mqttc.connect(mqttHost, 1883)
data = unicode(data, errors="replace")
data = data.decode(errors="replace")
mqttc.publish(topic, data)
mqttc.loop(2)
19 changes: 9 additions & 10 deletions examples/clients/PythonClient/pyClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
Turn a light on in the evening and off in the morning according to a schedule
"""

import urllib2
from datetime import datetime
import time
import syslog
import time
from urllib.error import HTTPError, URLError
from urllib.request import urlopen

######### Configuration #########

Expand All @@ -23,21 +24,19 @@
lightState = 2

while 1:

# Get the current hour
currentHour = datetime.now().hour

# Check to see if the system should be off
if (currentHour >= scheduleON or currentHour < scheduleOFF) and lightState != 1:

result = 0
# Connect to our sensor at 10.10.3.44:1000/ and request OFF
try:
response = urllib2.urlopen(requestOFF, None, 15) # 15 second time-out
response = urlopen(requestOFF, None, 15) # 15 second time-out
result = response.getcode()
except urllib2.HTTPError, e:
except HTTPError as e:
syslog.syslog("HTTPError = " + str(e.code))
except urllib2.URLError, e:
except URLError as e:
syslog.syslog("URLError = " + str(e.reason))
except Exception:
import traceback
Expand All @@ -54,11 +53,11 @@
result = 0

try:
response = urllib2.urlopen(requestON, None, 15) # 15 second time-out
response = urlopen(requestON, None, 15) # 15 second time-out
result = response.getcode()
except urllib2.HTTPError, e:
except HTTPError as e:
syslog.syslog("HTTPError = " + str(e.code))
except urllib2.URLError, e:
except URLError as e:
syslog.syslog("URLError = " + str(e.reason))
except Exception:
import traceback
Expand Down
3 changes: 0 additions & 3 deletions examples/ncurses/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,3 @@ target_link_libraries(${example} PUBLIC
${linked_libs}
${CURSES_LIBRARIES}
)
if("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" OR DEFINED RF24_NO_INTERRUPT)
target_compile_definitions(${example} PUBLIC RF24_NO_INTERRUPT)
endif()

0 comments on commit 21c5165

Please sign in to comment.