Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
pepe2k committed Dec 1, 2012
0 parents commit 5811f30
Show file tree
Hide file tree
Showing 14 changed files with 952 additions and 0 deletions.
163 changes: 163 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#################
## Eclipse
#################

*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# CDT-specific
.cproject

# PDT-specific
.buildpath


#################
## Visual Studio
#################

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User-specific files
*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover

## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf

# Visual Studio profiler
*.psess
*.vsp

# ReSharper is a .NET coding add-in
_ReSharper*

# Installshield output folder
[Ee]xpress

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish

# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML



############
## Windows
############

# Windows image file caches
Thumbs.db

# Folder config file
Desktop.ini


#############
## Python
#############

*.py[co]

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

#Mr Developer
.mr.developer.cfg

# Mac crap
.DS_Store
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
KLONE_VERSION = 3.1.0

export MAKL_DIR = $(shell pwd)/klone-${KLONE_VERSION}/build/makl
export MAKEFLAGS = -I$(MAKL_DIR)/mk

# add --enable_debug to enable debug
KLONE_CONF_ARGS += --enable_hooks

# webapp directory (must be absolute)
WEBAPP_DIR = $(CURDIR)/webapp

# also run make in the build directory (must be absolute paths)
SUBDIR = $(CURDIR)/lib

# include directories
WEBAPP_CFLAGS = -I$(CURDIR)/lib

# static libraries
WEBAPP_LDADD = $(CURDIR)/lib/librpigpiowebcp.a

# dynamic libraries
WEBAPP_LDFLAGS = -lrt -lbcm2835

include klapp.mk

klapp.mk: ; wget -O $@ -c http://koanlogic.com/klone/klapp.mk
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
RPi GPIO Web Control Panel
==========================

About
-----

This is a simple and light web control panel for manipulating GPIO ports in **Raspberry Pi**.

It is based on:

- **bcm2835** library - used for GPIO access (http://www.open.com.au/mikem/bcm2835/, GPLv2 license)
- **KoanLogic Srl KLone** - as a web server (http://www.koanlogic.com/klone/, Simplified BSD license)
- **jQuery** library - used for HTML DOM manipulation and animations (http://jquery.com/, MIT License)

Features
--------

- Simple HTML/CSS without any graphic files.
- You can define which of GPIO ports you want to use as an input and which as an output.
- Main page displays current status for all defined GPIO ports.
- You can change value for GPIO defined as output simply by click on its label.

Installation
------------

1. Give your Raspberry Pi access to the Internet.
2. Download and install **bcm2835** library from http://www.open.com.au/mikem/bcm2835/, make sure it is working!
3. Read about pin numbering in **bcm2835** library and something about **KLone** web server.
4. Download **RPi GPIO Web Control Panel** in zip archive, extract it.
5. Change declaration for GPIO ports in *lib/rpigpiowebcp.c* file (*gpio_outs[]* and *gpio_ins[]* arrays) or use default values.
6. Refer to KLone config file in *webapp/etc/kloned.conf*.
7. Run *make* and wait...
8. If everything went well run *sudo ./kloned -F* (this command will run KLone daemon in foreground mode) and go to your Raspberry Pi IP address in your browser.
9. CTRL+C to stop KLone daemon.

Future plans
------------

- Multi languages support (now only Polish).
- Access only for authorized users (login form, sessions).
- Change working mode from cyclic "polling" server for data to "push" data from server to browser.
- Change GPIO ports definition during operation and store settings in external file/files.
- Support for other GPIO manipulating libraries or make own.
- SPI, I2C, UART support.

ChangeLog
---------

- **1.0**: Initial release (01-12-2012)
16 changes: 16 additions & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# always include common.mk in MaKL-based makefiles
include common.mk

# include klone-related variables
include ../vars.mk

# name of the library
LIB = rpigpiowebcp

# list of source files
SRCS = rpigpiowebcp.c

# compilation flags
CFLAGS += -I ../include $(KLONE_CFLAGS)

include lib.mk
67 changes: 67 additions & 0 deletions lib/rpigpiowebcp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// rpigpiowebcp.c
// Author: Piotr Dymacz ([email protected])

#include "rpigpiowebcp.h"

/*
called when KLone server starts
prepares all defined GPIOs (mode and pull up/down in input mode or default value in output mode)
*/
int server_init( void ){
int i = 0;

if( bcm2835_init() ){

if( gpio_outs_num > 0 || gpio_ins_num > 0 ){

// GPIOs in output mode
for( i = 0; i < gpio_outs_num; i++ ){

bcm2835_gpio_fsel( gpio_outs[i].number, BCM2835_GPIO_FSEL_OUTP );

bcm2835_gpio_write( gpio_outs[i].number, gpio_outs[i].default_val );

}

// GPIOs in input mode
for( i = 0; i < gpio_ins_num; i++ ){

bcm2835_gpio_fsel( gpio_ins[i].number, BCM2835_GPIO_FSEL_INPT );

bcm2835_gpio_set_pud( gpio_ins[i].number, gpio_ins[i].mode );

}

} else {
printf( "Nie zdefiniowano żadnych portów GPIO.\n" );
exit( EXIT_FAILURE );
}

} else {
printf( "Wystąpił błąd przy inicjalizacji GPIO.\nSerwer musi być uruchomiony z uprawnieniami root.\n" );
exit( EXIT_FAILURE );
}

return 0;
}

/* user provided hooks setup */
void hooks_setup( void ){
hook_server_init( server_init );
}

// GPIOs in output mode definition
// Please, refer to pin numbering and constants in bcm2835 library!
extern RpiGpioWebCpOut gpio_outs[] = {
RPI_V2_GPIO_P1_11, "P1.11 in P1 connector (RPi rev. 2)", LOW
};

// GPIOs in input mode definition
// Please, refer to pin numbering and constants in bcm2835 library!
extern RpiGpioWebCpIn gpio_ins[] = {
RPI_V2_GPIO_P1_13, "P1.13 in P1 connector (RPi rev. 2)", BCM2835_GPIO_PUD_DOWN
};

// count defined GPIOs
extern int gpio_outs_num = sizeof(gpio_outs) / sizeof(RpiGpioWebCpOut);
extern int gpio_ins_num = sizeof(gpio_ins) / sizeof(RpiGpioWebCpIn);
37 changes: 37 additions & 0 deletions lib/rpigpiowebcp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// rpigpiowebcp.h
// Author: Piotr Dymacz ([email protected])

#ifndef RPIGPIOWEBCP_H
#define RPIGPIOWEBCP_H

#include <stdio.h>
#include <klone/klone.h>
#include <bcm2835.h>

#define RPIGPIOWEBCP_VERSION "ver. 1.0"

/* struct definition for single GPIO in output mode */
typedef struct {
RPiGPIOPin number;
const char* name;
uint8_t default_val;
} RpiGpioWebCpOut;

/* struct definition for single GPIO in input mode */
typedef struct {
RPiGPIOPin number;
const char* name;
bcm2835PUDControl mode;
} RpiGpioWebCpIn;

/* GPIO definition arrays */
extern RpiGpioWebCpOut gpio_outs[];
extern RpiGpioWebCpIn gpio_ins[];

/* number of defined GPIOs */
extern int gpio_outs_num;
extern int gpio_ins_num;

int server_init( void );

#endif /* RPIGPIOWEBCP_H */
22 changes: 22 additions & 0 deletions webapp/etc/kloned.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server_list app_http
allow_root yes

log
{
type file
file.basename /tmp/kloned_log
}

app_http
{
type http

addr tcp4://*:80
dir_root /www

access_log
{
type file
file.basename /tmp/kloned_access_log
}
}
Loading

0 comments on commit 5811f30

Please sign in to comment.