Skip to content

Commit dadf4b9

Browse files
author
hutorny
committed
v1.1
1 parent 106bc59 commit dadf4b9

File tree

142 files changed

+17791
-1278
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+17791
-1278
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ integral part and uses many feature, itroduced in cojson.
1818
serving `GET` requests from browsers, `GET/PUT/POST` requests from JavaScript via
1919
`XMLHttpRequest` and simple machine-to-machine communications.
2020

21+
### JSON-RPC
22+
`μcuREST` implements `JSON-RPC 2.0` specification, enabling easy implementation
23+
of RPC for MCU applications over HTTP protocol.
24+
2125
### Transport Layer
2226

2327
An application, implementing HTTP RESTful services with `μcuREST` needs a
@@ -46,15 +50,35 @@ the HTTP message size could be limited to size of one MTU (~1460 bytes).
4650
complexity, taking in average 750 bytes of ROM and 250 bytes of RAM per
4751
entry.
4852

53+
### Arduino Library
54+
55+
`μcuREST` library for Arduino is available for downloading on this
56+
[`link`](https://raw.githubusercontent.com/hutorny/download/master/Micurest_Arduino.zip)
57+
58+
### Particle Library
59+
60+
`μcuREST` library for Spark Particle is available for downloading on this
61+
[`link`](https://raw.githubusercontent.com/hutorny/download/master/Micurest_Particle.zip)
62+
4963
### Tested On
5064
* **Debian** `i686`, `g++-4.9.2`
5165
* **Controllino MAXI** `ATmega2560`, `avr-g++-4.8.1`
5266
* **NodeMCU V3** `ESP8266` `xtensa-lx106-elf-g++-4.8.5`
67+
* **Particle Photon** `STM32F205RGY6` `arm-none-eabi-g++-4.9.3`
68+
69+
### Prebuilt Demos
70+
71+
Ready for flashing example applications can be downloaded via these links:
72+
73+
* **Controllino MAXI** [`atmega2560.controllino_maxi.micurest_demo.zip`](https://github.com/hutorny/download/raw/master/atmega2560.controllino_maxi.micurest_demo.zip)
74+
* **NodeMCU V3** [`esp8266.nodemcu_v3.micurest_demo.zip`](https://github.com/hutorny/download/raw/master/esp8266.nodemcu_v3.micurest_demo.zip)
75+
* **Particle Photon** [`stm32f2.photon.micurest_demo.zip`](https://github.com/hutorny/download/raw/master/stm32f2.photon.micurest_demo.zip)
5376

5477
Please visit project's [`home page`](http://hutorny.in.ua/projects/micurest)
5578
and [`tutorial`](http://hutorny.in.ua/projects/micurest-tutorial) for more
5679
details
5780

81+
-------------------------------------------------------------------------------
5882

5983
## cojson
6084
C++ pull-type `JSON` parser/generator for constrained platforms

changelog.v.1.1.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## µcuREST change log v.1.1
2+
3+
`ADD` Implemented lwIP session layer (network_lwip.cpp)
4+
`MOD` Refactored miculog
5+
`MOD` Complteted JSON-RPC implementation - µcuRPC
6+
`ADD` JSON-RPC example for Arduino Mega 2560
7+
`ADD` Example for lwIP
8+
`MOD` removed unused abstractions from network.hpp
9+
`MOD` refactored network layers to make them consisten across all platforms
10+
`ADD` session layer for spark
11+
`ADD` Particle Photon examples
12+
`MOD` refactored configuration to use CCS
13+
`MOD` refactored headers to use pragma once instead of guards
14+
`ADD` µcuREST tutorial
15+
16+
## cojson change log
17+
`MOD` fixed bug with JSON 4HEXDIG
18+
`MOD` fixed PropertyConstString to accept cstring
19+
`MOD` fixed null pointer accessing with PropertyString*
20+
`ADD` cojson::Read/Write template functions

examples/arduino_mega2560/arduino_mega2560.ino

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const directory& resourceMap() noexcept {
5151
/* define an application instance associated with the map */
5252
application rest(resourceMap());
5353

54-
/* instance of a tcp server, bbound to port 80 */
55-
network_arduino::proto::tcp server(80);
54+
/* instance of a tcp server, running the rest application */
55+
network_arduino::tcp::server server(rest);
5656
static uint8_t mac[]={0xC2,0xB5,0x52,0x45,0x53,0x54};
5757
void setup() {
5858
pinMode(LED_BUILTIN, OUTPUT);
@@ -63,17 +63,10 @@ void setup() {
6363
Ethernet.begin(mac);
6464
Serial.print("server IP is ");
6565
Serial.println(Ethernet.localIP());
66-
// start listening
67-
server.listen();
66+
// start listening on port 80
67+
server.listen(80);
6868
}
6969

7070
void loop() {
71-
if( server.accept() ) {
72-
Serial.print(".");
73-
// start HTTP session
74-
network_arduino::proto::tcp::connection client(server);
75-
// service HTTP request using rest application
76-
network::proto::http::service(client, rest);
77-
}
78-
71+
server.run();
7972
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
#include "miculog.ccs"
3+
#include "access_log.ccs"
4+
#include "network_arduino.ccs"
5+
6+
namespace configuration {
7+
struct Current : Is<target::All, build::Default> {};
8+
template<> struct Selector<micurest::network_arduino::tcp::server> : Current {};
9+
template<> struct Selector<micurest::network::access_log> : Current {};
10+
}
11+
12+
namespace miculog {
13+
14+
template<> struct ClassLogLevels<
15+
micurest::network_arduino::tcp::server,
16+
configuration::build::Default> :
17+
From<level::warn> {};
18+
19+
template<> struct ClassLogLevels<
20+
micurest::network_arduino::tcp::server,
21+
configuration::build::Debug> :
22+
Levels<level::debug, level::info, level::error> {};
23+
24+
template<> struct ClassLogLevels<
25+
micurest::network::access_log,
26+
configuration::build::Default> :
27+
Levels<> {};
28+
29+
template<> struct ClassLogLevels<
30+
micurest::network::access_log,
31+
configuration::build::Debug> :
32+
Levels<level::info> {};
33+
}
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
# Copyright (C) 2017 Eugene Hutorny <eugene@hutorny.in.ua>
2+
#
3+
# Makefile - make script to build µcuREST example for Controllino MAXI
4+
#
5+
# This file is part of µcuREST Library. http://hutorny.in.ua/projects/micurest
6+
#
7+
# The µcuREST Library is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU General Public License v2
9+
# as published by the Free Software Foundation;
10+
#
11+
# The µcuREST Library is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
# See the GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with the COJSON Library; if not, see
18+
# <http://www.gnu.org/licenses/gpl-2.0.html>.
19+
20+
PREFIX ?= avr-
21+
CC := @$(PREFIX)gcc$(SUFFIX)
22+
CXX := @$(PREFIX)g++$(SUFFIX)
23+
LD := @$(PREFIX)g++$(SUFFIX)
24+
ASM := @$(PREFIX)gcc$(SUFFIX)
25+
OBJ := @$(PREFIX)objcopy
26+
SIZE:= @$(PREFIX)size
27+
BOLD:=$(shell tput bold)
28+
NORM:=$(shell tput sgr0)
29+
BUILD-DIR ?= /tmp/$(USER)/micurest/example/arduino/
30+
VARIANT ?= mega
31+
FIND = find /opt/arduino* \( -readable -or \! -prune \) \
32+
\( -type f -o -type l \) -name $(PREFIX)g++$(SUFFIX) | tail -1
33+
34+
MAKEFLAGS += --no-builtin-rules
35+
36+
-include arduino.vars
37+
export PATH
38+
39+
#ARDUINO-DIR ?=/opt/arduino
40+
CORE-DIR ?=$(ARDUINO-DIR)/hardware/arduino/avr/cores/arduino
41+
VARIANT-DIR ?=$(ARDUINO-DIR)/hardware/arduino/avr/variants/$(VARIANT)
42+
ETHERNET-DIR ?=$(ARDUINO-DIR)/libraries/Ethernet/src
43+
SPI-DIR ?=$(ARDUINO-DIR)/hardware/arduino/avr/libraries/SPI
44+
45+
AVRDUDE_FLAGS += \
46+
-D \
47+
-C/etc/avrdude.conf \
48+
-patmega2560 \
49+
-cwiring \
50+
-b115200 \
51+
$(if $(AVRDUDE_PORT),-P $(AVRDUDE_PORT)) \
52+
53+
CXX-DEFS := \
54+
ARDUINO=164 \
55+
F_CPU=16000000UL \
56+
ARDUINO_ARCH_AVR \
57+
ARDUINO_AVR_MEGA2560 \
58+
59+
INCLUDES += \
60+
$(realpath .) \
61+
$(realpath ../../include) \
62+
$(realpath ../../src) \
63+
$(VARIANT-DIR) \
64+
$(CORE-DIR) \
65+
$(ETHERNET-DIR) \
66+
$(SPI-DIR) \
67+
68+
CPPFLAGS += \
69+
$(addprefix -I,$(INCLUDES)) \
70+
$(addprefix -D,$(CXX-DEFS)) \
71+
-std=c++1y \
72+
-Wall \
73+
-Os \
74+
-fshort-enums \
75+
-ffunction-sections \
76+
-fdata-sections \
77+
-funsigned-bitfields \
78+
-fno-rtti \
79+
-fno-exceptions \
80+
-fno-threadsafe-statics \
81+
-fno-use-cxa-atexit \
82+
-mmcu=atmega2560 \
83+
84+
85+
CFLAGS += \
86+
$(addprefix -I,$(INCLUDES)) \
87+
$(addprefix -D,$(CXX-DEFS)) \
88+
-std=gnu11 \
89+
-Os \
90+
-fpack-struct \
91+
-fshort-enums \
92+
-ffunction-sections \
93+
-fdata-sections \
94+
-funsigned-bitfields \
95+
-mmcu=atmega2560 \
96+
97+
LIBS += c gcc hal pp phy net80211 lwip m wpa main ssl
98+
99+
LDFLAGS += \
100+
-Wl,-Map,bin/micurest-example.map,--cref \
101+
-mrelax \
102+
-Wl,--gc-sections \
103+
-mmcu=atmega2560 \
104+
105+
OFLAGS += \
106+
-R .eeprom \
107+
-R .fuse \
108+
-R .lock \
109+
-R .signature \
110+
-O ihex \
111+
112+
113+
SFLAGS := \
114+
--format=avr \
115+
--mcu=atmega2560 \
116+
117+
EXAMPLE-OBJS := \
118+
arduino_mega2560_rpc.o \
119+
avrcppfix.o \
120+
121+
MICUREST-OBJS := \
122+
cojson.o \
123+
cojson_libdep.o \
124+
cojson_progmem.o \
125+
micurpc.o \
126+
micurest.o \
127+
micurest_progmem.o \
128+
miculog_arduino.o \
129+
network_arduino.o \
130+
chartypetable_progmem.o \
131+
132+
ARDUINO-OBJS := \
133+
HardwareSerial.o \
134+
HardwareSerial0.o \
135+
SPI.o \
136+
IPAddress.o \
137+
Dns.o \
138+
Dhcp.o \
139+
Tone.o \
140+
Ethernet.o \
141+
EthernetClient.o \
142+
EthernetServer.o \
143+
EthernetUdp.o \
144+
Print.o \
145+
hooks.o \
146+
main.o \
147+
wiring.o \
148+
wiring_digital.o \
149+
wiring_analog.o \
150+
socket.o \
151+
w5100.o \
152+
WMath.o \
153+
154+
OBJS += $(addprefix $(BUILD-DIR),$(MICUREST-OBJS) $(ARDUINO-OBJS) $(EXAMPLE-OBJS))
155+
156+
# prerequisites
157+
PREREQ := \
158+
$(BUILD-DIR) \
159+
bin \
160+
161+
# arduino.vars \
162+
163+
$(BUILD-DIR)cojson.o : FILE-FLAGS:=-pedantic
164+
$(BUILD-DIR)cojson_libdep.o : FILE-FLAGS:=-pedantic
165+
$(BUILD-DIR)cojson_progmem.o : FILE-FLAGS:=-pedantic
166+
$(BUILD-DIR)micurpc.o : FILE-FLAGS:=-pedantic
167+
$(BUILD-DIR)micurest.o : FILE-FLAGS:=-pedantic
168+
$(BUILD-DIR)micurest_progmem.o : FILE-FLAGS:=-pedantic
169+
$(BUILD-DIR)miculog_arduino.o : FILE-FLAGS:=-pedantic
170+
$(BUILD-DIR)network_arduino.o : FILE-FLAGS:=-pedantic
171+
$(BUILD-DIR)chartypetable_progmem.o : FILE-FLAGS:=-pedantic
172+
$(BUILD-DIR)Dns.o : FILE-FLAGS:=-Wno-strict-aliasing
173+
174+
vpath %.cpp user:../../src/:$(CORE-DIR):$(ETHERNET-DIR):$(ETHERNET-DIR)/utility:$(SPI-DIR)
175+
vpath %.c user:$(CORE-DIR):$(ARDUINO-DIR):$(ETHERNET-DIR):$(SPI-DIR)
176+
177+
.DEFAULT:
178+
179+
.SUFFIXES:
180+
.SUFFIXES: .elf .o .size .bin .hex .elf .o
181+
182+
.SECONDARY:
183+
184+
.PHONY: bin
185+
186+
all: $(PREREQ) bin/arduino_mega_2560.hex
187+
188+
bin:
189+
@mkdir -p $@
190+
191+
$(BUILD-DIR):
192+
@mkdir -p $@
193+
194+
bin/%.elf: $(OBJS) | $(PREREQ)
195+
@echo " $(BOLD)ld$(NORM) " $(notdir $@)
196+
$(LD) $(LDFLAGS) -o $@ $^
197+
@chmod a-x $@
198+
199+
bin/%.hex: bin/%.elf | $(PREREQ)
200+
@echo "$(BOLD)objcopy$(NORM)" $(notdir $@)
201+
$(OBJ) $(OFLAGS) $< $@
202+
$(SIZE) $(SFLAGS) $<
203+
204+
$(BUILD-DIR)%.o: %.c | $(PREREQ)
205+
@echo " $(BOLD)cc$(NORM)" $(notdir $<)
206+
$(CC) $(CFLAGS) $(FILE-FLAGS) -c -o $@ $<
207+
208+
$(BUILD-DIR)%.o: %.cpp | $(PREREQ)
209+
@echo " $(BOLD)c++$(NORM)" $(notdir $<)
210+
$(CXX) $(CPPFLAGS) $(FILE-FLAGS) -c -o $@ $<
211+
212+
arduino.vars:
213+
@$(if $(filter-out clean,$(MAKECMDGOALS),$(if $(MAKECMDGOALS),,true)), \
214+
$(if $(ARDUINO-DIR), \
215+
echo ARDUINO-DIR:=$(ARDUINO-DIR) > $@;, \
216+
$(error ARDUINO-DIR is not set)) \
217+
echo "# lookup for $(PREFIX)g++$(SUFFIX)" >> $@; \
218+
$(if $(shell which $(PREFIX)g++$(SUFFIX)), \
219+
echo "# found in path\n# "$(shell which $(PREFIX)g++$(SUFFIX)) >>$@;,\
220+
echo PATH=$(dir $(shell $(FIND))):$$PATH >> $@))
221+
222+
help:
223+
@echo $(CORE-DIR):$(ARDUINO-DIR):$(ETHERNET-DIR)
224+
@echo \
225+
"\nUsage:\n\t$(BOLD)make$(NORM) ARDUINO-DIR=/path-to-arduino-studio\n" \
226+
227+
run: bin/arduino_mega_2560.hex
228+
@echo " $(BOLD)flash$(NORM) " $^ \
229+
$(if $(AVRDUDE_PORT),, "(AVRDUDE_PORT not set, using default port)")
230+
avrdude $(AVRDUDE_FLAGS) -Uflash:w:@$^:i
231+
232+
clean:
233+
@rm -f $(BUILD-DIR)/*.o $(BUILD-DIR)/*.map $(BUILD-DIR)/*.size \
234+
bin/*.hex bin/*.elf
235+
236+
distclean: clean
237+
@rm -f package library arduino.vars
238+
@rm -rf bin $(BUILD-DIR)
239+

0 commit comments

Comments
 (0)