Skip to content

Commit

Permalink
Merge pull request #3 from mec-kon/dev
Browse files Browse the repository at this point in the history
added mqtt support / multiple device support
  • Loading branch information
mec-kon authored Nov 3, 2019
2 parents e8f76b0 + e93a942 commit dc2e0cf
Show file tree
Hide file tree
Showing 23 changed files with 12,920 additions and 8,239 deletions.
32 changes: 29 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,48 @@ project(led-strip-server)
EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
message( STATUS "detected architecture: ${ARCHITECTURE}" )

if(${CMAKE_BUILD_TYPE} MATCHES Debug)
add_definitions(-DDEBUG_MODE)
message("Debug Build")
elseif(${CMAKE_BUILD_TYPE} MATCHES Release)
message("Release Build")
endif()

if( ${ARCHITECTURE} STREQUAL "x86_64" )
# added -pthread
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
else()
# added -pthread -lwiringPi
# added -pthread -lwiringPi on Rasperry Pi
add_definitions(-DIS_RASPBERRY_PI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -lwiringPi")
endif()

# in order to use mqtt, libmosquittopp must be installed
option(USE_MQTT "use mqtt in project" ON)


file(GLOB_RECURSE SRC_CXX_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp ${PROJECT_SOURCE_DIR}/src/*/*.cpp)
file(GLOB_RECURSE SRC_HEADERS ${PROJECT_SOURCE_DIR}/src/*.h ${PROJECT_SOURCE_DIR}/src/*/*.h )

# in order to use mqtt, libmosquittopp must be installed
if(USE_MQTT)
add_definitions(-DUSE_MQTT)
message(STATUS "mqtt enabled")
else()
list(REMOVE_ITEM SRC_CXX_FILES ${PROJECT_SOURCE_DIR}/src/communication/Mqtt.cpp)
message(STATUS "mqtt disabled")
endif()

add_executable(${PROJECT_NAME}
${SRC_C_FILES} ${SRC_CXX_FILES} ${SRC_HEADERS})
${SRC_CXX_FILES} ${SRC_HEADERS})

# in order to use mqtt, libmosquittopp must be installed
if(USE_MQTT)
target_link_libraries(${PROJECT_NAME} mosquittopp)
endif()

install (TARGETS ${PROJECT_NAME} DESTINATION /usr/local/bin/)
install (DIRECTORY static/src DESTINATION $ENV{HOME}/.${PROJECT_NAME})
install (DIRECTORY config DESTINATION $ENV{HOME}/.${PROJECT_NAME})
install(CODE "execute_process(COMMAND sudo chown -c $ENV{USER} $ENV{HOME}/.led-strip-server/src/deviceConfig.json)")
install(CODE "execute_process(COMMAND sudo chown -c $ENV{USER} $ENV{HOME}/.led-strip-server/config/websiteConfig.json)")
install(CODE "execute_process(COMMAND sudo chown -c $ENV{USER} $ENV{HOME}/.led-strip-server/config/websiteConfig.json)")
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# led-strip-server
### This is a simple server program for a Raspberry Pi that hosts a web page to select different colors on it.
### These colors are then displayed on an RGB led strip.
### In addition, the server can receive commands over MQTT to control the led strip from Openhab.

![](demo/led_strip_website.png)

Expand All @@ -15,25 +16,28 @@ Modes
Three different modes are currently available.
* The one color mode allows you to select a simple color.
* The fade mode can be used to smoothly transition inbetween several selected colors.
of the LED strip moves.
* The changing colors mode switches between all selected colors.

## Download ##
Download the server ```git clone https://github.com/mec-kon/led-strip-server.git```
Then navigate into the server folder with ```cd led-strip-server```.
Initialize the submodules with ```git submodule update --init```

## Config ##
To use the server, you must change the ip address of the server.
You can do this by typing ```nano static/src/deviceConfig.json```.

## Installation: ##
The easiest way to install the program is with CMake.
The easiest way to build the program is with CMake.

First you need to install all required dependencies.
You can do this with ```sudo apt-get install cmake wiringpi build-essential```.

You will also need to install libmosquittopp if you want to use mqtt in this project.
You can do this with ```sudo apt-get install libmosquittopp-dev```.

Then, all you have to do is create a new folder with ```mkdir build``` in the current project folder, change to this folder with ```cd build``` and create a makefile
with ```cmake .. -DCMAKE_BUILD_TYPE=Debug``` .
with ```cmake ..``` or ```cmake .. -DUSE_MQTT=OFF``` if you don't want to use mqtt .
Then you can create the executables by simply typing ```make```
Now install the server with ```sudo make install```.

Expand All @@ -51,6 +55,15 @@ Restart the Raspberry Pi.
Next type ```crontab -e```.
In the window that opens, add the line "@reboot /usr/local/bin/led-strip-server".

### Openhab ###

To receive commands from Openhab, the following files must be added or modified in "/etc/openhab2/":
* create "color.items" in "/etc/openhab2/items"
* modify "default.sitemap" in "/etc/openhab2/sitemaps"
* create "color.rules" in "/etc/openhab2/rules"

The mentioned files can be found <a href="https://gist.github.com/mec-kon/e4c0c31d593cc22c0699b9fac8d17851" target="_blank">here</a>

Pull requests
--------

Expand Down
2 changes: 1 addition & 1 deletion config/websiteConfig.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"port":9999}
{"port":9999, "mqttPort":1883}
Binary file modified demo/led_strip_website.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dc2e0cf

Please sign in to comment.