Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructuring project dirs and files #24

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Executable
coap
microcoap

# Object files
*.o
Expand Down Expand Up @@ -33,3 +33,6 @@ coap
*.i*86
*.x86_64
*.hex

# OS system files
.directory
22 changes: 0 additions & 22 deletions Makefile

This file was deleted.

13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ Endpoint handlers are defined in endpoints.c
For linux/OSX

make
./coap
./microcoap

For Arduino

open microcoap.ino
copy libraries and microcoap-example directories to the Arduino IDE sketches folder (or just change the sketches folder to the microcoap dir)
open: File -> sketches folder -> microcoap-example

Arduino LED pin defined at `microcoap-example\connections.h` and set to `13` (default embedded led for some Arduino boards)

To test, use libcoap

Expand All @@ -32,6 +35,12 @@ To test, use libcoap
Or use copper (Firefox plugin)

coap://127.0.0.1

How to add new coap links
======================

Use `microcoap-example` dir and edit it or prepare similar folder.
Edit `endpoints.h` and `endpoints.c` similar to light entry.

Arduino problem
===============
Expand Down
12 changes: 12 additions & 0 deletions microcoap-example/connections.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef CONNECTIONS_H
#define CONNECTIONS 1
#ifdef __cplusplus
extern "C" {
#endif

#define LED 13

#ifdef __cplusplus
}
#endif
#endif // CONNECTIONS
10 changes: 5 additions & 5 deletions endpoints.c → microcoap-example/endpoints.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdbool.h>
#include <string.h>
#include "coap.h"
#include "microcoap.h"
#include "connections.h"

static char light = '0';

Expand All @@ -10,10 +11,9 @@ void build_rsp(void);

#ifdef ARDUINO
#include "Arduino.h"
static int led = 6;
void endpoint_setup(void)
{
pinMode(led, OUTPUT);
pinMode(LED, OUTPUT);
build_rsp();
}
#else
Expand Down Expand Up @@ -44,7 +44,7 @@ static int handle_put_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpk
{
light = '1';
#ifdef ARDUINO
digitalWrite(led, HIGH);
digitalWrite(LED, HIGH);
#else
printf("ON\n");
#endif
Expand All @@ -54,7 +54,7 @@ static int handle_put_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpk
{
light = '0';
#ifdef ARDUINO
digitalWrite(led, LOW);
digitalWrite(LED, LOW);
#else
printf("OFF\n");
#endif
Expand Down
15 changes: 15 additions & 0 deletions microcoap-example/endpoints.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef ENDPOINTS_H
#define ENDPOINTS_H 1
#ifdef __cplusplus
extern "C" {
#endif

#include "microcoap.h"

static int handle_get_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo);
static int handle_put_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo);

#ifdef __cplusplus
}
#endif
#endif // ENDPOINTS_H
3 changes: 2 additions & 1 deletion microcoap.ino → microcoap-example/microcoap-example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <Ethernet.h>
#include <stdint.h>
#include <EthernetUdp.h>
#include "coap.h"
#include "endpoints.h"
#include "microcoap.h"

#define PORT 5683
static uint8_t mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
Expand Down
3 changes: 2 additions & 1 deletion coap.c → microcoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include <stdbool.h>
#include <string.h>
#include <stddef.h>
#include "coap.h"
#include "microcoap.h"

extern void endpoint_setup(void);
extern void increment_tick(void);
extern const coap_endpoint_t endpoints[];

#ifdef DEBUG
Expand Down
7 changes: 4 additions & 3 deletions coap.h → microcoap.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef COAP_H
#define COAP_H 1
#ifndef MICROCOAP_H
#define MICROCOAP_H 1

#ifdef __cplusplus
extern "C" {
extern "C" {
#endif

#include <stdint.h>
Expand Down Expand Up @@ -165,6 +165,7 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_
void coap_option_nibble(uint32_t value, uint8_t *nibble);
void coap_setup(void);
void endpoint_setup(void);
void increment_tick(void); // FIXME: create cpp wrapper

#ifdef __cplusplus
}
Expand Down
30 changes: 30 additions & 0 deletions src-posix/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# make -> compile microcoap app
# make clean -> remove the app file and all object files (.o)
# make all -> clean and compile
APPNAME = microcoap
SRC = main-posix.c \
../microcoap.c \
../microcoap-example/endpoints.c
# compilation options
CFLAGS = -Wall -DDEBUG
INC_DIR = ../ \
../microcoap-example
# -DIPV6

# how to compile individual object files
OBJS = $(SRC:.c=.o)
.c.o:
$(CC) $(CFLAGS) -I$(INC_DIR) -c $< -o $@

.PHONY: all clean

# app compilation
$(APPNAME): $(OBJS) $(SRC)
$(CC) $(OBJS) -o $(APPNAME)

# cleaning rule
clean:
rm -f $(OBJS) $(APPNAME) *~

# additional rule
all: clean $(APPNAME)
2 changes: 1 addition & 1 deletion main-posix.c → src-posix/main-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdbool.h>
#include <strings.h>

#include "coap.h"
#include "microcoap.h"

#define PORT 5683

Expand Down