├── .gitignore ├── NEWS ├── TODO.md ├── Documentation ├── SampleIMST.jpg ├── SampleSigfox.png ├── QuickStart-Empty.png ├── QuickStart-List.png ├── QuickStart-Plot.png ├── QuickStart-Content.png ├── SampleProximusMyThings.png ├── SampleTheThingsNetwork.png ├── SampleIMST.log └── Compilation.md ├── Resources ├── AtomITLogoDocumentation.png ├── Orthanc │ ├── README.txt │ ├── MinGW-W64-Toolchain32.cmake │ ├── MinGW-W64-Toolchain64.cmake │ ├── MinGWToolchain.cmake │ └── LinuxStandardBaseToolchain.cmake ├── ThirdParty │ └── tiny-AES-c-master │ │ ├── URL.txt │ │ ├── Makefile │ │ ├── aes.h │ │ ├── unlicense.txt │ │ └── README.md ├── Docker │ ├── setup-debian.sh │ ├── create-config.sh │ ├── download-atomit.sh │ ├── Dockerfile │ └── Graveyard │ │ ├── Dockerfile │ │ └── build.sh ├── SyncOrthancFolder.py └── CMake │ ├── RaspberryPiToolchain.cmake │ ├── IMSTGateway.cmake │ └── PahoMQTT.cmake ├── AUTHORS ├── Framework ├── TimeSeries │ ├── SQLiteBackend │ │ ├── PrepareDatabase.sql │ │ ├── SQLiteTimeSeriesBackend.h │ │ ├── SQLiteDatabase.h │ │ └── SQLiteTimeSeriesTransaction.h │ ├── ITimeSeriesObserver.h │ ├── ITimeSeriesFactory.h │ ├── MemoryBackend │ │ ├── MemoryTimeSeriesBackend.h │ │ └── MemoryTimeSeriesContent.h │ ├── ITimeSeriesAccessor.h │ ├── ITimeSeriesManager.h │ ├── TimeSeriesWriter.h │ ├── TimeSeriesReader.h │ ├── GenericTimeSeriesManager.h │ └── ITimeSeriesBackend.h ├── AtomITEnumerations.h ├── Filters │ ├── DemultiplexerFilter.h │ ├── IFilter.h │ ├── LoRaPacketFilter.h │ ├── MQTTSinkFilter.h │ ├── FileLinesSourceFilter.h │ ├── CSVFileSourceFilter.h │ ├── MQTTSourceFilter.h │ ├── FileReaderFilter.h │ ├── IMSTSourceFilter.h │ ├── DemultiplexerFilter.cpp │ ├── FileLinesSourceFilter.cpp │ ├── CounterSourceFilter.h │ ├── CSVFileSinkFilter.h │ ├── HttpPostSinkFilter.h │ ├── HttpPostSinkFilter.cpp │ ├── MQTTSinkFilter.cpp │ ├── MQTTSourceFilter.cpp │ ├── LuaFilter.h │ ├── SharedFileSinkFilter.h │ ├── FileReaderFilter.cpp │ ├── SharedFileSinkFilter.cpp │ ├── AdapterFilter.h │ ├── CounterSourceFilter.cpp │ ├── CSVFileSinkFilter.cpp │ └── SourceFilter.h ├── LoRa │ ├── LoRaEnumerations.h │ ├── LoRaToolbox.h │ ├── PHYPayload.h │ ├── FrameEncryptionKey.h │ ├── UnsignedInteger128.h │ ├── LoRaEnumerations.cpp │ └── MACPayload.h ├── AtomITToolbox.h ├── FileWritersPool.h ├── MQTT │ ├── Broker.h │ ├── SynchronousClient.h │ ├── MQTTClientWrapper.h │ └── MQTTClientWrapper.cpp ├── Message.h ├── Message.cpp └── ConfigurationSection.h ├── WebInterface ├── explorer.html ├── content.html ├── content.js ├── chart.html ├── chart.js └── explorer.js ├── UnitTestsSources └── UnitTests.cpp ├── Applications ├── FilterFactory.h ├── AtomITRestApi.h └── ServerContext.h └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | ThirdPartyDownloads 3 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 2017-12-12 5 | ========== 6 | 7 | * Initial release 8 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | * 500 error if `PUT` after end of the time series 2 | * Delete whole time series in REST 3 | -------------------------------------------------------------------------------- /Documentation/SampleIMST.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodogne/atomit/HEAD/Documentation/SampleIMST.jpg -------------------------------------------------------------------------------- /Documentation/SampleSigfox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodogne/atomit/HEAD/Documentation/SampleSigfox.png -------------------------------------------------------------------------------- /Documentation/QuickStart-Empty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodogne/atomit/HEAD/Documentation/QuickStart-Empty.png -------------------------------------------------------------------------------- /Documentation/QuickStart-List.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodogne/atomit/HEAD/Documentation/QuickStart-List.png -------------------------------------------------------------------------------- /Documentation/QuickStart-Plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodogne/atomit/HEAD/Documentation/QuickStart-Plot.png -------------------------------------------------------------------------------- /Documentation/QuickStart-Content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodogne/atomit/HEAD/Documentation/QuickStart-Content.png -------------------------------------------------------------------------------- /Resources/AtomITLogoDocumentation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodogne/atomit/HEAD/Resources/AtomITLogoDocumentation.png -------------------------------------------------------------------------------- /Documentation/SampleProximusMyThings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodogne/atomit/HEAD/Documentation/SampleProximusMyThings.png -------------------------------------------------------------------------------- /Documentation/SampleTheThingsNetwork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jodogne/atomit/HEAD/Documentation/SampleTheThingsNetwork.png -------------------------------------------------------------------------------- /Resources/Orthanc/README.txt: -------------------------------------------------------------------------------- 1 | This folder contains an excerpt of the source code of Orthanc. It is 2 | automatically generated using the "../SyncOrthancFolder.py" script. 3 | -------------------------------------------------------------------------------- /Resources/ThirdParty/tiny-AES-c-master/URL.txt: -------------------------------------------------------------------------------- 1 | https://github.com/kokke/tiny-AES-c 2 | 3 | license = public domain 4 | 5 | 6 | https://en.wikipedia.org/wiki/AES_implementations#C.2FASM_library 7 | -------------------------------------------------------------------------------- /Resources/Docker/setup-debian.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | cd 5 | 6 | # Setup Debian 7 | DEBIAN_FRONTEND=noninteractive apt-get update 8 | DEBIAN_FRONTEND=noninteractive apt-get install -y wget 9 | 10 | rm -rf /var/lib/apt/lists/* 11 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Atom-IT - Lightweight, RESTful microservice for IoT 2 | =================================================== 3 | 4 | 5 | Authors 6 | ------- 7 | 8 | * Sebastien Jodogne 9 | 10 | Overall design and lead developer. 11 | 12 | * WSL S.A. 13 | Liege Science Park 14 | Rue des Chasseurs Ardennais, 3 15 | B-4031 ANGLEUR 16 | -------------------------------------------------------------------------------- /Resources/Docker/create-config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | cd 5 | 6 | # Create the various directories 7 | mkdir /etc/atomit 8 | mkdir -p /var/lib/atomit/db 9 | 10 | # Create a basic configuration 11 | cat << EOF > /etc/atomit/atomit.json 12 | { 13 | "AutoTimeSeries" : { }, // Automatic use of the memory backend 14 | "HttpPort" : 8042, 15 | "RemoteAccessAllowed" : true, 16 | "AuthenticationEnabled" : true, 17 | "RegisteredUsers" : { 18 | "atomit" : "atomit" 19 | }, 20 | "TimeSeries" : { 21 | // "hello" : { 22 | // "Backend" : "SQLite", 23 | // "Path" : "/var/lib/atomit/db/hello.db" 24 | //} 25 | } 26 | } 27 | EOF 28 | -------------------------------------------------------------------------------- /Resources/Docker/download-atomit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | cd 5 | 6 | URL=http://lsb.orthanc-server.com/ 7 | VERSION_ATOMIT=mainline 8 | 9 | # Download binaries compiled with Linux Standard Base 10 | wget ${URL}/atomit/${VERSION_ATOMIT}/AtomIT 11 | wget ${URL}/atomit/${VERSION_ATOMIT}/UnitTests 12 | 13 | chmod +x ./AtomIT 14 | chmod +x ./UnitTests 15 | 16 | # Run the unit tests 17 | mkdir ~/UnitTestsRun 18 | cd ~/UnitTestsRun 19 | ../UnitTests 20 | 21 | # Recover space used by the unit tests 22 | cd 23 | rm -f ./UnitTests 24 | 25 | # Move the binaries to their final location 26 | mkdir -p /usr/local/sbin/ 27 | 28 | mv ./AtomIT /usr/local/sbin/ 29 | -------------------------------------------------------------------------------- /Resources/Docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:wheezy-slim 2 | 3 | MAINTAINER Sebastien Jodogne 4 | LABEL Description="Atom-IT, lightweight server for IoT" Vendor="WSL" 5 | 6 | WORKDIR /root/ 7 | 8 | ADD ./setup-debian.sh ./setup-debian.sh 9 | RUN bash ./setup-debian.sh 10 | 11 | ADD ./download-atomit.sh ./download-atomit.sh 12 | RUN bash ./download-atomit.sh 13 | 14 | ADD ./create-config.sh ./create-config.sh 15 | RUN bash ./create-config.sh 16 | 17 | RUN rm ./download-atomit.sh ./create-config.sh ./setup-debian.sh 18 | 19 | VOLUME [ "/var/lib/atomit/db", "/etc/atomit" ] 20 | EXPOSE 8042 21 | 22 | ENTRYPOINT [ "AtomIT" ] 23 | CMD [ "/etc/atomit/atomit.json" ] 24 | -------------------------------------------------------------------------------- /Resources/Orthanc/MinGW-W64-Toolchain32.cmake: -------------------------------------------------------------------------------- 1 | # the name of the target operating system 2 | set(CMAKE_SYSTEM_NAME Windows) 3 | 4 | # which compilers to use for C and C++ 5 | set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) 6 | set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) 7 | set(CMAKE_RC_COMPILER i686-w64-mingw32-windres) 8 | 9 | # here is the target environment located 10 | set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) 11 | 12 | # adjust the default behaviour of the FIND_XXX() commands: 13 | # search headers and libraries in the target environment, search 14 | # programs in the host environment 15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 18 | -------------------------------------------------------------------------------- /Resources/Orthanc/MinGW-W64-Toolchain64.cmake: -------------------------------------------------------------------------------- 1 | # the name of the target operating system 2 | set(CMAKE_SYSTEM_NAME Windows) 3 | 4 | # which compilers to use for C and C++ 5 | set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) 6 | set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) 7 | set(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) 8 | 9 | # here is the target environment located 10 | set(CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32) 11 | 12 | # adjust the default behaviour of the FIND_XXX() commands: 13 | # search headers and libraries in the target environment, search 14 | # programs in the host environment 15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 18 | -------------------------------------------------------------------------------- /Framework/TimeSeries/SQLiteBackend/PrepareDatabase.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE GlobalProperties( 2 | property INTEGER PRIMARY KEY, 3 | value TEXT 4 | ); 5 | 6 | CREATE TABLE TimeSeries( 7 | internalId INTEGER PRIMARY KEY AUTOINCREMENT, 8 | publicId TEXT, 9 | maxLength INTEGER, 10 | maxSize INTEGER, 11 | currentLength INTEGER, 12 | currentSize INTEGER, 13 | lastTimestamp INTEGER 14 | ); 15 | 16 | CREATE TABLE Content( 17 | id INTEGER REFERENCES TimeSeries(internalId) ON DELETE CASCADE, 18 | timestamp INTEGER, 19 | size INTEGER, 20 | metadata TEXT, 21 | value TEXT, 22 | PRIMARY KEY(id, timestamp) 23 | ); 24 | 25 | CREATE INDEX TimeSeriesIndex ON TimeSeries(publicId); 26 | -------------------------------------------------------------------------------- /Resources/Docker/Graveyard/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:3.7 2 | 3 | MAINTAINER Sebastien Jodogne 4 | LABEL Description="Atom-IT server" Vendor="Sebastien Jodogne, WSL S.A." 5 | 6 | ADD ./build.sh /root/build.sh 7 | 8 | # Install the build dependencies and compile Atom-IT in one single 9 | # Docker layer, using the "group dependencies" feature to keep track 10 | # of what to be uninstalled after compilation 11 | RUN apk --update add --no-cache --virtual .build-dependencies \ 12 | g++ gcc cmake unzip tar git bash make e2fsprogs-dev python \ 13 | && bash /root/build.sh "master" \ 14 | && apk del .build-dependencies 15 | 16 | # Make sure to have the C++ standard and UUID libraries available 17 | RUN apk --update add --no-cache libstdc++ e2fsprogs 18 | 19 | VOLUME [ "/var/lib/atomit/db" ] 20 | EXPOSE 8042 21 | 22 | ENTRYPOINT [ "AtomIT" ] 23 | CMD [ "/etc/atomit/atomit.json" ] 24 | -------------------------------------------------------------------------------- /WebInterface/explorer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Atom-IT server 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 |

Content of the Atom-IT server

20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Resources/Orthanc/MinGWToolchain.cmake: -------------------------------------------------------------------------------- 1 | # the name of the target operating system 2 | set(CMAKE_SYSTEM_NAME Windows) 3 | 4 | # which compilers to use for C and C++ 5 | set(CMAKE_C_COMPILER i586-mingw32msvc-gcc) 6 | set(CMAKE_CXX_COMPILER i586-mingw32msvc-g++) 7 | set(CMAKE_RC_COMPILER i586-mingw32msvc-windres) 8 | 9 | # here is the target environment located 10 | set(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc) 11 | 12 | # adjust the default behaviour of the FIND_XXX() commands: 13 | # search headers and libraries in the target environment, search 14 | # programs in the host environment 15 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 18 | 19 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTACK_SIZE_PARAM_IS_A_RESERVATION=0x10000" CACHE INTERNAL "" FORCE) 20 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTACK_SIZE_PARAM_IS_A_RESERVATION=0x10000" CACHE INTERNAL "" FORCE) 21 | -------------------------------------------------------------------------------- /Resources/ThirdParty/tiny-AES-c-master/Makefile: -------------------------------------------------------------------------------- 1 | #CC = avr-gcc 2 | #CFLAGS = -Wall -mmcu=atmega16 -Os -Wl,-Map,test.map 3 | #OBJCOPY = avr-objcopy 4 | CC = gcc 5 | CFLAGS = -Wall -Os -Wl,-Map,test.map 6 | OBJCOPY = objcopy 7 | 8 | # include path to AVR library 9 | INCLUDE_PATH = /usr/lib/avr/include 10 | # splint static check 11 | SPLINT = splint test.c aes.c -I$(INCLUDE_PATH) +charindex -unrecog 12 | 13 | .SILENT: 14 | .PHONY: lint clean 15 | 16 | 17 | rom.hex : test.out 18 | # copy object-code to new image and format in hex 19 | $(OBJCOPY) -j .text -O ihex test.out rom.hex 20 | 21 | test.o : test.c 22 | # compiling test.c 23 | $(CC) $(CFLAGS) -c test.c -o test.o 24 | 25 | aes.o : aes.h aes.c 26 | # compiling aes.c 27 | $(CC) $(CFLAGS) -c aes.c -o aes.o 28 | 29 | test.out : aes.o test.o 30 | # linking object code to binary 31 | $(CC) $(CFLAGS) aes.o test.o -o test.out 32 | 33 | small: test.out 34 | $(OBJCOPY) -j .text -O ihex test.out rom.hex 35 | 36 | clean: 37 | rm -f *.OBJ *.LST *.o *.gch *.out *.hex *.map 38 | 39 | lint: 40 | $(call SPLINT) 41 | -------------------------------------------------------------------------------- /WebInterface/content.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Atom-IT server 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 |

Content of time series:

20 | 21 |

22 | Back to the list of time series 23 |

24 | 25 |

26 | Plot this time series 27 |

28 | 29 |

30 |   31 |

32 | 33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /Resources/SyncOrthancFolder.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # 4 | # This maintenance script updates the content of the "Orthanc" folder 5 | # to match the latest version of the Orthanc source code. 6 | # 7 | 8 | import multiprocessing 9 | import os 10 | import stat 11 | import urllib2 12 | 13 | TARGET = os.path.join(os.path.dirname(__file__), 'Orthanc') 14 | REPOSITORY = 'https://bitbucket.org/sjodogne/orthanc/raw' 15 | 16 | FILES = [ 17 | 'DownloadOrthancFramework.cmake', 18 | 'LinuxStandardBaseToolchain.cmake', 19 | 'MinGW-W64-Toolchain32.cmake', 20 | 'MinGW-W64-Toolchain64.cmake', 21 | 'MinGWToolchain.cmake', 22 | ] 23 | 24 | 25 | def Download(x): 26 | branch = x[0] 27 | source = x[1] 28 | target = os.path.join(TARGET, x[2]) 29 | print target 30 | 31 | try: 32 | os.makedirs(os.path.dirname(target)) 33 | except: 34 | pass 35 | 36 | url = '%s/%s/%s' % (REPOSITORY, branch, source) 37 | 38 | with open(target, 'w') as f: 39 | f.write(urllib2.urlopen(url).read()) 40 | 41 | 42 | commands = [] 43 | 44 | for f in FILES: 45 | commands.append([ 'default', 46 | os.path.join('Resources', f), 47 | f ]) 48 | 49 | pool = multiprocessing.Pool(10) # simultaneous downloads 50 | pool.map(Download, commands) 51 | -------------------------------------------------------------------------------- /Resources/ThirdParty/tiny-AES-c-master/aes.h: -------------------------------------------------------------------------------- 1 | #ifndef _AES_H_ 2 | #define _AES_H_ 3 | 4 | #include 5 | 6 | 7 | // #define the macros below to 1/0 to enable/disable the mode of operation. 8 | // 9 | // CBC enables AES encryption in CBC-mode of operation. 10 | // ECB enables the basic ECB 16-byte block algorithm. Both can be enabled simultaneously. 11 | 12 | // The #ifndef-guard allows it to be configured before #include'ing or at compile time. 13 | #ifndef CBC 14 | #define CBC 1 15 | #endif 16 | 17 | #ifndef ECB 18 | #define ECB 1 19 | #endif 20 | 21 | #define AES128 1 22 | //#define AES192 1 23 | //#define AES256 1 24 | 25 | #if defined(ECB) && (ECB == 1) 26 | 27 | void AES_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length); 28 | void AES_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output, const uint32_t length); 29 | 30 | #endif // #if defined(ECB) && (ECB == !) 31 | 32 | 33 | #if defined(CBC) && (CBC == 1) 34 | 35 | void AES_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 36 | void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 37 | 38 | #endif // #if defined(CBC) && (CBC == 1) 39 | 40 | 41 | #endif //_AES_H_ 42 | -------------------------------------------------------------------------------- /Resources/ThirdParty/tiny-AES-c-master/unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /Resources/Docker/Graveyard/build.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | set -e 4 | 5 | # Get the number of available cores to speed up the build 6 | COUNT_CORES=`grep -c ^processor /proc/cpuinfo` 7 | echo "Will use $COUNT_CORES parallel jobs to build the Atom-IT server" 8 | 9 | # Create the various directories as in official Debian packages 10 | mkdir /etc/atomit 11 | mkdir -p /var/lib/atomit/db 12 | 13 | # Clone the Atom-IT repository and switch to the requested branch 14 | cd /root/ 15 | git clone https://github.com/jodogne/atomit.git atomit 16 | cd atomit 17 | echo "Switching to branch: $1" 18 | git checkout "$1" 19 | 20 | # Build the Atom-IT server 21 | mkdir Build 22 | cd Build 23 | cmake \ 24 | -DALLOW_DOWNLOADS=ON \ 25 | -DCMAKE_BUILD_TYPE:STRING=Release \ 26 | -DSTATIC_BUILD=ON \ 27 | -DENABLE_IMST_GATEWAY=OFF \ 28 | -DCMAKE_CXX_FLAGS="-Wno-deprecated-declarations" \ 29 | .. 30 | make -j$COUNT_CORES 31 | 32 | # Run the unit tests 33 | ./UnitTests 34 | 35 | # Install the Atom-IT server 36 | make install 37 | 38 | # Remove the build directory to recover space 39 | cd /root/ 40 | rm -rf /root/atomit 41 | 42 | # Generate a minimal configuration file 43 | CONFIG=/etc/atomit/atomit.json 44 | 45 | cat < $CONFIG 46 | { 47 | "AutoTimeSeries" : { }, // Automatic use of the memory backend 48 | "HttpPort" : 8042, 49 | "RemoteAccessAllowed" : true, 50 | "AuthenticationEnabled" : true, 51 | "RegisteredUsers" : { 52 | "atomit" : "atomit" 53 | } 54 | } 55 | EOF 56 | -------------------------------------------------------------------------------- /WebInterface/content.js: -------------------------------------------------------------------------------- 1 | function GetArgument(name) { 2 | var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href); 3 | if (results == null){ 4 | return null; 5 | } 6 | else { 7 | return results[1] || 0; 8 | } 9 | } 10 | 11 | $(document).ready(function() { 12 | var series = GetArgument('id'); 13 | $('#series').text(series); 14 | $('#chart').attr('href', 'chart.html?id=' + encodeURIComponent(series)); 15 | 16 | $.ajax({ 17 | url: '../series/' + series + '/content?limit=0', 18 | cache: false, 19 | success: function(data) { 20 | var source = []; 21 | 22 | for (var i = 0; i < data.content.length; i++) { 23 | var item = data.content[i]; 24 | 25 | var value; 26 | 27 | if (item.value.length >= 128) 28 | { 29 | value = '(too long)'; 30 | } 31 | else 32 | { 33 | value = item.value; 34 | 35 | if (item.base64) 36 | { 37 | value += ' (base64)'; 38 | } 39 | } 40 | 41 | var line = [ item.timestamp, 42 | item.metadata, 43 | value ]; 44 | 45 | source.push(line); 46 | } 47 | 48 | $('#content').DataTable({ 49 | data: source, 50 | columns: [ 51 | { title: 'Timestamp' }, 52 | { title: 'Metadata' }, 53 | { title: 'Value' } 54 | ], 55 | 'pageLength': 25 56 | }); 57 | } 58 | }); 59 | 60 | 61 | }); 62 | -------------------------------------------------------------------------------- /WebInterface/chart.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Atom-IT server 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 |

Plot of time series:

20 | 21 |

22 | Back to the list of time series 23 |

24 | 25 |

26 | Open the raw content of this time series 27 |

28 | 29 |

30 |   31 |

32 | 33 |
34 | 35 |

The chart is interactive:

36 | 37 |
    38 |
  • 39 | You can mouse over to highlight individual values. 40 |
  • 41 |
  • 42 | You can click and drag to zoom. 43 |
  • 44 |
  • 45 | Double-clicking will zoom you back out. 46 |
  • 47 |
  • 48 | Shift-drag will pan. 49 |
  • 50 |

    51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /WebInterface/chart.js: -------------------------------------------------------------------------------- 1 | function GetArgument(name) { 2 | var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href); 3 | if (results == null){ 4 | return null; 5 | } 6 | else { 7 | return results[1] || 0; 8 | } 9 | } 10 | 11 | $(document).ready(function() { 12 | var series = GetArgument('id'); 13 | $('#series').text(series); 14 | $('#raw').attr('href', 'content.html?id=' + encodeURIComponent(series)); 15 | 16 | $.ajax({ 17 | url: '../series/' + series + '/content?limit=0', 18 | cache: false, 19 | success: function(data) { 20 | var source = []; 21 | 22 | for (var i = 0; i < data.content.length; i++) { 23 | var item = data.content[i]; 24 | 25 | if (!item.binary) { 26 | var value = parseFloat(item.value); 27 | if (!isNaN(value)) { 28 | source.push([ item.timestamp, value ]); 29 | } 30 | } 31 | } 32 | 33 | if (source.length == 0) { 34 | alert('This time series has no numeric payload!'); 35 | } 36 | 37 | // http://dygraphs.com/data.html#array 38 | g = new Dygraph(document.getElementById('content'), 39 | source, { 40 | labels: [ 'Timestamp', 'Value' ] 41 | //legend: 'always', 42 | //title: 'Values', 43 | //showRoller: true, 44 | //rollPeriod: 14, 45 | //customBars: true, 46 | //ylabel: 'Temperature (F)' 47 | }); 48 | } 49 | }); 50 | 51 | }); 52 | -------------------------------------------------------------------------------- /Resources/CMake/RaspberryPiToolchain.cmake: -------------------------------------------------------------------------------- 1 | ## 2 | ## CMake toolchain for Raspberry Pi, using Crosstool-NG 3 | ## http://crosstool-ng.github.io/ 4 | ## https://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/ 5 | ## 6 | ## Usage: 7 | ## cmake -DCROSSTOOLS_ROOT=/home/jodogne/x-tools/ -DSTATIC_BUILD=ON -DCMAKE_TOOLCHAIN_FILE=../Resources/CMake/RaspberryPiToolchain.cmake -DCMAKE_BUILD_TYPE=Release .. 8 | ## 9 | 10 | if (NOT DEFINED CROSSTOOLS_ROOT) 11 | # If not given at the CMake invokation, use the default target 12 | # location of Crosstool-NG (i.e. "~/x-tools", where the user 13 | # directory "~" is retrieved by reading the USER environment 14 | # variable) 15 | set(CROSSTOOLS_ROOT "/home/$ENV{USER}/x-tools") 16 | endif() 17 | 18 | if (NOT DEFINED CROSSTOOLS_ARCHITECTURE) 19 | set(CROSSTOOLS_ARCHITECTURE arm-unknown-linux-gnueabi) 20 | endif() 21 | 22 | # the name of the target operating system 23 | set(CMAKE_SYSTEM_NAME Linux) 24 | 25 | # which compilers to use for C and C++ 26 | set(CMAKE_C_COMPILER ${CROSSTOOLS_ROOT}/${CROSSTOOLS_ARCHITECTURE}/bin/${CROSSTOOLS_ARCHITECTURE}-gcc) 27 | set(CMAKE_CXX_COMPILER ${CROSSTOOLS_ROOT}/${CROSSTOOLS_ARCHITECTURE}/bin/${CROSSTOOLS_ARCHITECTURE}-g++) 28 | 29 | # here is the target environment located 30 | set(CMAKE_FIND_ROOT_PATH ${CROSSTOOLS_PATH}/${CROSSTOOLS_ARCHITECTURE}) 31 | 32 | # adjust the default behaviour of the FIND_XXX() commands: 33 | # search headers and libraries in the target environment, search 34 | # programs in the host environment 35 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 36 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 37 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 38 | -------------------------------------------------------------------------------- /Resources/CMake/IMSTGateway.cmake: -------------------------------------------------------------------------------- 1 | if (ENABLE_IMST_GATEWAY) 2 | 3 | # WARNING: Release 3.1.0 does not work with RPi! Necessary to use the mainline version 4 | 5 | set(IMST_GATEWAY_SOURCES_DIR ${CMAKE_BINARY_DIR}/lora_gateway-2017-09-13) 6 | DownloadPackage( 7 | "0548d61d760bceec4a6380e6c093b5bd" 8 | "http://www.orthanc-server.com/downloads/third-party/atom-it/lora_gateway-2017-09-13.tar.gz" 9 | "${IMST_GATEWAY_SOURCES_DIR}") 10 | 11 | file(WRITE 12 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/inc/config.h 13 | " 14 | #pragma once 15 | #define LIBLORAGW_VERSION \"4.0.0\" 16 | #define CFG_SPI_NATIVE 1 17 | #define DEBUG_AUX 0 18 | #define DEBUG_SPI 0 19 | #define DEBUG_REG 0 20 | #define DEBUG_HAL 0 21 | #define DEBUG_GPS 0 22 | #define DEBUG_GPIO 23 | #define DEBUG_LBT 0 24 | #include \"imst_rpi.h\" 25 | ") 26 | 27 | include_directories( 28 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/inc/ 29 | ) 30 | 31 | set(IMST_GATEWAY_SOURCES 32 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/src/loragw_aux.c 33 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/src/loragw_fpga.c 34 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/src/loragw_gps.c 35 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/src/loragw_hal.c 36 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/src/loragw_lbt.c 37 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/src/loragw_radio.c 38 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/src/loragw_reg.c 39 | ${IMST_GATEWAY_SOURCES_DIR}/libloragw/src/loragw_spi.native.c 40 | ) 41 | 42 | source_group(ThirdParty\\lora_gateway REGULAR_EXPRESSION ${IMST_GATEWAY_SOURCES_DIR}/.*) 43 | 44 | add_definitions(-DATOMIT_ENABLE_IMST_GATEWAY=1) 45 | 46 | else() 47 | add_definitions(-DATOMIT_ENABLE_IMST_GATEWAY=0) 48 | 49 | endif() 50 | -------------------------------------------------------------------------------- /Framework/AtomITEnumerations.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | namespace AtomIT 35 | { 36 | enum TimestampType 37 | { 38 | TimestampType_Default, 39 | TimestampType_Sequence, 40 | TimestampType_NanosecondsClock, 41 | TimestampType_MillisecondsClock, 42 | TimestampType_SecondsClock, 43 | TimestampType_Fixed 44 | }; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /UnitTestsSources/UnitTests.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include 33 | 34 | #include 35 | 36 | int main(int argc, char **argv) 37 | { 38 | Orthanc::Logging::Initialize(); 39 | Orthanc::Logging::EnableInfoLevel(true); 40 | 41 | ::testing::InitGoogleTest(&argc, argv); 42 | int result = RUN_ALL_TESTS(); 43 | 44 | Orthanc::Logging::Finalize(); 45 | 46 | return result; 47 | } 48 | -------------------------------------------------------------------------------- /Applications/FilterFactory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "../Framework/ConfigurationSection.h" 35 | #include "../Framework/FileWritersPool.h" 36 | #include "../Framework/TimeSeries/ITimeSeriesManager.h" 37 | #include "../Framework/Filters/IFilter.h" 38 | 39 | namespace AtomIT 40 | { 41 | IFilter* CreateFilter(ITimeSeriesManager& manager, 42 | FileWritersPool& writers, 43 | const ConfigurationSection& config); 44 | } 45 | -------------------------------------------------------------------------------- /Framework/TimeSeries/ITimeSeriesObserver.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace AtomIT 38 | { 39 | class ITimeSeriesObserver : public boost::noncopyable 40 | { 41 | public: 42 | virtual ~ITimeSeriesObserver() 43 | { 44 | } 45 | 46 | virtual void NotifySeriesDeleted(const std::string& name) = 0; 47 | 48 | virtual void NotifySeriesModified(const std::string& name) = 0; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /Framework/TimeSeries/SQLiteBackend/SQLiteTimeSeriesBackend.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "SQLiteTimeSeriesTransaction.h" 35 | #include "../ITimeSeriesBackend.h" 36 | 37 | namespace AtomIT 38 | { 39 | class SQLiteTimeSeriesBackend : public ITimeSeriesBackend 40 | { 41 | private: 42 | class Transaction; 43 | 44 | SQLiteDatabase& database_; 45 | std::string name_; 46 | 47 | public: 48 | SQLiteTimeSeriesBackend(SQLiteDatabase& database, 49 | const std::string& name); 50 | 51 | virtual ITransaction* CreateTransaction(bool isReadOnly); 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /Framework/TimeSeries/ITimeSeriesFactory.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "ITimeSeriesBackend.h" 35 | #include "../AtomITEnumerations.h" 36 | 37 | #include 38 | 39 | namespace AtomIT 40 | { 41 | class ITimeSeriesFactory : public boost::noncopyable 42 | { 43 | public: 44 | virtual ~ITimeSeriesFactory() 45 | { 46 | } 47 | 48 | virtual void ListManualTimeSeries(std::map& target) = 0; 49 | 50 | virtual ITimeSeriesBackend* CreateManualTimeSeries(const std::string& name) = 0; 51 | 52 | virtual ITimeSeriesBackend* CreateAutoTimeSeries(TimestampType& timestampType /* out */, 53 | const std::string& name) = 0; 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /WebInterface/explorer.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | 3 | $.ajax({ 4 | url: '../series', 5 | cache: false, 6 | success: function(series) { 7 | var data = []; 8 | 9 | $.each(series.sort(), function(index, value) { 10 | 11 | $.ajax({ 12 | url: '../series/' + value + '/statistics', 13 | cache: false, 14 | async: false, 15 | success: function(statistics) { 16 | data.push([ 17 | value, 18 | statistics.length, 19 | statistics.size, 20 | value, 21 | value 22 | ]); 23 | 24 | $('#series').append($('

    ').text('Time series: ' + value)); 25 | var ul = $('
      '); 26 | ul.append($('
    • ').text('Number of items: ' + statistics.length)); 27 | ul.append($('
    • ').text('Size on disk: ' + statistics.size + ' bytes')); 28 | ul.append($('
    • ').append($('') 29 | .attr('href', 'content.html?id=' + value) 30 | .text('Open content'))); 31 | ul.append($('
    • ').append($('') 32 | .attr('href', 'chart.html?id=' + value) 33 | .text('Plot time series'))); 34 | $('#series').append(ul); 35 | } 36 | }); 37 | }); 38 | 39 | $('#content').DataTable({ 40 | data: data, 41 | columns: [ 42 | { title: 'Time series' }, 43 | { title: 'Length' }, 44 | { title: 'Size on disk' }, 45 | { title: 'Open content' }, 46 | { title: 'Plot time series' } 47 | ], 48 | 'pageLength': 25, 49 | 'columnDefs': [ 50 | { 'className': 'dt-center', 'targets': '_all' }, 51 | { 52 | targets: 3, 53 | render: function(data, type, row, meta) { 54 | return 'Open'; 55 | } 56 | }, 57 | { 58 | targets: 4, 59 | render: function(data, type, row, meta) { 60 | return 'Plot'; 61 | } 62 | } 63 | ] 64 | }); 65 | } 66 | }); 67 | }); 68 | -------------------------------------------------------------------------------- /Framework/Filters/DemultiplexerFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "AdapterFilter.h" 35 | 36 | namespace AtomIT 37 | { 38 | class DemultiplexerFilter : public AdapterFilter 39 | { 40 | public: 41 | typedef std::map ConvertedMessages; 42 | 43 | private: 44 | ITimeSeriesManager& manager_; 45 | 46 | protected: 47 | virtual void Demux(ConvertedMessages& outputs, 48 | const Message& source) = 0; 49 | 50 | virtual PushStatus Push(const Message& message); 51 | 52 | public: 53 | DemultiplexerFilter(const std::string& name, 54 | ITimeSeriesManager& manager, 55 | const std::string& inputTimeSeries); 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /Framework/Filters/IFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | namespace AtomIT 38 | { 39 | class IFilter : public boost::noncopyable 40 | { 41 | public: 42 | virtual ~IFilter() 43 | { 44 | } 45 | 46 | virtual std::string GetName() const = 0; 47 | 48 | virtual void Start() = 0; 49 | 50 | // "Step()" must have bounded execution time to cleanly stop the 51 | // filter thread (ideally, no more than 500ms). The method is 52 | // allowed to throw exceptions. A return value of "false" 53 | // indicates that the filter has ended its task, and should not be 54 | // re-executed. 55 | virtual bool Step() = 0; 56 | 57 | virtual void Stop() = 0; 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /Framework/Filters/LoRaPacketFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "AdapterFilter.h" 35 | #include "../LoRa/FrameEncryptionKey.h" 36 | 37 | namespace AtomIT 38 | { 39 | class LoRaPacketFilter : public AdapterFilter 40 | { 41 | private: 42 | TimeSeriesWriter writer_; 43 | LoRa::FrameEncryptionKey nwkSKey_; 44 | LoRa::FrameEncryptionKey appSKey_; 45 | 46 | protected: 47 | virtual PushStatus Push(const Message& message); 48 | 49 | public: 50 | LoRaPacketFilter(const std::string& name, 51 | ITimeSeriesManager& manager, 52 | const std::string& inputTimeSeries, 53 | const std::string& outputTimeSeries, 54 | const std::string& nwkSKey, 55 | const std::string& appSKey); 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /Resources/CMake/PahoMQTT.cmake: -------------------------------------------------------------------------------- 1 | if (STATIC_BUILD OR NOT USE_SYSTEM_PAHO) 2 | set(PAHO_SOURCES_DIR ${CMAKE_BINARY_DIR}/paho.mqtt.c-1.2.0) 3 | DownloadPackage( 4 | "6897eea98dc0a0e6fd6bed4dd3a4bbe5" 5 | "http://www.orthanc-server.com/downloads/third-party/atom-it/paho.mqtt.c-1.2.0.tar.gz" 6 | "${PAHO_SOURCES_DIR}") 7 | 8 | configure_file( 9 | ${PAHO_SOURCES_DIR}/src/VersionInfo.h.in 10 | ${AUTOGENERATED_DIR}/VersionInfo.h 11 | ) 12 | 13 | set(PAHO_SOURCES 14 | ${PAHO_SOURCES_DIR}/src/Clients.c 15 | ${PAHO_SOURCES_DIR}/src/Heap.c 16 | ${PAHO_SOURCES_DIR}/src/LinkedList.c 17 | ${PAHO_SOURCES_DIR}/src/Log.c 18 | ${PAHO_SOURCES_DIR}/src/MQTTPacket.c 19 | ${PAHO_SOURCES_DIR}/src/MQTTPacketOut.c 20 | ${PAHO_SOURCES_DIR}/src/MQTTPersistence.c 21 | ${PAHO_SOURCES_DIR}/src/MQTTPersistenceDefault.c 22 | ${PAHO_SOURCES_DIR}/src/MQTTProtocolClient.c 23 | ${PAHO_SOURCES_DIR}/src/MQTTProtocolOut.c 24 | ${PAHO_SOURCES_DIR}/src/Messages.c 25 | ${PAHO_SOURCES_DIR}/src/Socket.c 26 | ${PAHO_SOURCES_DIR}/src/SocketBuffer.c 27 | ${PAHO_SOURCES_DIR}/src/StackTrace.c 28 | ${PAHO_SOURCES_DIR}/src/Thread.c 29 | ${PAHO_SOURCES_DIR}/src/Tree.c 30 | ${PAHO_SOURCES_DIR}/src/utf-8.c 31 | 32 | # We use the synchronous version of Paho 33 | #${PAHO_SOURCES_DIR}/src/MQTTAsync.c 34 | ${PAHO_SOURCES_DIR}/src/MQTTClient.c 35 | 36 | # We include SSL support 37 | ${PAHO_SOURCES_DIR}/src/SSLSocket.c 38 | ) 39 | 40 | include_directories( 41 | ${PAHO_SOURCES_DIR}/src 42 | ) 43 | 44 | if (CMAKE_SYSTEM_NAME STREQUAL "Windows") 45 | add_definitions(-D_WINDOWS) 46 | if (CMAKE_SIZEOF_VOID_P EQUAL "4") 47 | add_definitions(-DWIN32) 48 | elseif(CMAKE_SIZEOF_VOID_P EQUAL "8") 49 | add_definitions(-DWIN64) 50 | else() 51 | message(FATAL_ERROR "Unknown architecture") 52 | endif() 53 | endif() 54 | 55 | else() 56 | # in "paho-mqtt3cs", "c" means "MQTTClient" (not async) and "s" 57 | # means "with SSL support" 58 | set(PAHO_LIBRARY paho-mqtt3cs) 59 | 60 | CHECK_INCLUDE_FILE_CXX(MQTTClient.h HAVE_PAHO_H) 61 | if (NOT HAVE_PAHO_H) 62 | message(FATAL_ERROR "Please install the paho-devel package") 63 | endif() 64 | 65 | CHECK_LIBRARY_EXISTS(${PAHO_LIBRARY} MQTTClient_create "" HAVE_PAHO_LIB) 66 | if (NOT HAVE_PAHO_LIB) 67 | message(FATAL_ERROR "Please install the paho-devel package") 68 | endif() 69 | 70 | link_libraries(${PAHO_LIBRARY}) 71 | endif() 72 | -------------------------------------------------------------------------------- /Framework/Filters/MQTTSinkFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "AdapterFilter.h" 35 | #include "../MQTT/MQTTClientWrapper.h" 36 | 37 | namespace AtomIT 38 | { 39 | class MQTTSinkFilter : public AdapterFilter 40 | { 41 | private: 42 | MQTT::MQTTClientWrapper client_; 43 | 44 | protected: 45 | virtual PushStatus Push(const Message& message); 46 | 47 | public: 48 | MQTTSinkFilter(const std::string& name, 49 | ITimeSeriesManager& manager, 50 | const std::string& timeSeries); 51 | 52 | void SetBroker(const MQTT::Broker& broker) 53 | { 54 | client_.SetBroker(broker); 55 | } 56 | 57 | void SetClientId(const std::string& clientId) 58 | { 59 | client_.SetClientId(clientId); 60 | } 61 | 62 | virtual void Start(); 63 | 64 | virtual void Stop(); 65 | }; 66 | } 67 | -------------------------------------------------------------------------------- /Framework/LoRa/LoRaEnumerations.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | namespace AtomIT 35 | { 36 | namespace LoRa 37 | { 38 | enum MessageType 39 | { 40 | MessageType_ConfirmedDataDown, 41 | MessageType_ConfirmedDataUp, 42 | MessageType_JoinAccept, 43 | MessageType_JoinRequest, 44 | MessageType_Proprietary, 45 | MessageType_Reserved, // RFU 46 | MessageType_UnconfirmedDataDown, 47 | MessageType_UnconfirmedDataUp 48 | }; 49 | 50 | enum MessageDirection 51 | { 52 | MessageDirection_Uplink, // From device to gateway 53 | MessageDirection_Downlink // From gateway to device 54 | }; 55 | 56 | const char* EnumerationToString(MessageType type); 57 | 58 | const char* EnumerationToString(MessageDirection direction); 59 | 60 | MessageDirection GetMessageDirection(MessageType type); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Framework/Filters/FileLinesSourceFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "FileReaderFilter.h" 35 | 36 | namespace AtomIT 37 | { 38 | class FileLinesSourceFilter : public FileReaderFilter 39 | { 40 | private: 41 | std::string metadata_; 42 | 43 | protected: 44 | virtual FetchStatus ReadMessage(Message& message, 45 | boost::filesystem::ifstream& stream); 46 | 47 | public: 48 | FileLinesSourceFilter(const std::string& name, 49 | ITimeSeriesManager& manager, 50 | const std::string& timeSeries, 51 | const boost::filesystem::path& path); 52 | 53 | void SetMetadata(const std::string& metadata) 54 | { 55 | metadata_ = metadata; 56 | } 57 | 58 | const std::string& GetMetadata() const 59 | { 60 | return metadata_; 61 | } 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /Framework/TimeSeries/MemoryBackend/MemoryTimeSeriesBackend.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "MemoryTimeSeriesContent.h" 35 | #include "../ITimeSeriesBackend.h" 36 | 37 | #include 38 | 39 | namespace AtomIT 40 | { 41 | class MemoryTimeSeriesBackend : public ITimeSeriesBackend 42 | { 43 | private: 44 | class ReadOnlyTransaction; 45 | class ReadWriteTransaction; 46 | 47 | typedef boost::shared_mutex Mutex; 48 | typedef boost::shared_lock ReadLock; 49 | typedef boost::unique_lock WriteLock; 50 | 51 | Mutex mutex_; 52 | MemoryTimeSeriesContent content_; 53 | 54 | public: 55 | MemoryTimeSeriesBackend(uint64_t maxLength, 56 | uint64_t maxSize) : 57 | content_(maxLength, maxSize) 58 | { 59 | } 60 | 61 | virtual ITransaction* CreateTransaction(bool isReadOnly); 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /Framework/Filters/CSVFileSourceFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "FileReaderFilter.h" 35 | 36 | namespace AtomIT 37 | { 38 | class CSVFileSourceFilter : public FileReaderFilter 39 | { 40 | private: 41 | bool base64_; 42 | 43 | bool Decode(Message& message, 44 | const std::string& line) const; 45 | 46 | protected: 47 | virtual FetchStatus ReadMessage(Message& message, 48 | boost::filesystem::ifstream& stream); 49 | 50 | public: 51 | CSVFileSourceFilter(const std::string& name, 52 | ITimeSeriesManager& manager, 53 | const std::string& timeSeries, 54 | const boost::filesystem::path& path); 55 | 56 | void SetBase64Encoded(bool enable) 57 | { 58 | base64_ = enable; 59 | } 60 | 61 | bool IsBase64Encoded() const 62 | { 63 | return base64_; 64 | } 65 | }; 66 | } 67 | -------------------------------------------------------------------------------- /Framework/LoRa/LoRaToolbox.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | 36 | namespace AtomIT 37 | { 38 | namespace LoRa 39 | { 40 | namespace LoRaToolbox 41 | { 42 | template 43 | static inline T CeilingDivision(T a, 44 | unsigned int b) 45 | { 46 | if (a % b == 0) 47 | { 48 | return a / b; 49 | } 50 | else 51 | { 52 | return a / b + 1; 53 | } 54 | } 55 | 56 | void ParseHexadecimal(std::string& buffer, 57 | const std::string& message); 58 | 59 | std::string FormatHexadecimal(const void* buffer, 60 | size_t size, 61 | bool upcase); 62 | 63 | std::string FormatHexadecimal(const std::string& buffer, 64 | bool upcase); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Framework/Filters/MQTTSourceFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "SourceFilter.h" 35 | #include "../MQTT/MQTTClientWrapper.h" 36 | 37 | namespace AtomIT 38 | { 39 | class MQTTSourceFilter : public SourceFilter 40 | { 41 | private: 42 | MQTT::MQTTClientWrapper client_; 43 | 44 | protected: 45 | virtual FetchStatus Fetch(Message& message); 46 | 47 | public: 48 | MQTTSourceFilter(const std::string& name, 49 | ITimeSeriesManager& manager, 50 | const std::string& timeSeries); 51 | 52 | void SetBroker(const MQTT::Broker& broker) 53 | { 54 | client_.SetBroker(broker); 55 | } 56 | 57 | void SetClientId(const std::string& clientId) 58 | { 59 | client_.SetClientId(clientId); 60 | } 61 | 62 | void AddTopic(const std::string& topic) 63 | { 64 | client_.AddTopic(topic); 65 | } 66 | 67 | virtual void Start(); 68 | 69 | virtual void Stop(); 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /Framework/AtomITToolbox.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | namespace Toolbox 41 | { 42 | int64_t GetNanosecondsClockTimestamp(); 43 | 44 | int64_t GetMillisecondsClockTimestamp(); 45 | 46 | int64_t GetSecondsClockTimestamp(); 47 | 48 | bool XmlToJson(Json::Value& json, 49 | const std::string& xml, 50 | bool simplify); 51 | 52 | class FileWriter : public boost::noncopyable 53 | { 54 | private: 55 | boost::filesystem::ofstream stream_; 56 | bool isEmpty_; 57 | 58 | public: 59 | FileWriter(boost::filesystem::path path, 60 | bool append, 61 | bool binary); 62 | 63 | bool IsEmpty() 64 | { 65 | return isEmpty_; 66 | } 67 | 68 | void Write(const std::string& buffer); 69 | }; 70 | } 71 | } 72 | 73 | -------------------------------------------------------------------------------- /Framework/Filters/FileReaderFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "SourceFilter.h" 35 | 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | class FileReaderFilter : public SourceFilter 41 | { 42 | private: 43 | boost::filesystem::path path_; 44 | boost::filesystem::ifstream stream_; 45 | uint64_t line_; 46 | 47 | protected: 48 | virtual FetchStatus ReadMessage(Message& message, 49 | boost::filesystem::ifstream& stream) = 0; 50 | 51 | virtual FetchStatus Fetch(Message& message); 52 | 53 | public: 54 | FileReaderFilter(const std::string& name, 55 | ITimeSeriesManager& manager, 56 | const std::string& timeSeries, 57 | const boost::filesystem::path& path); 58 | 59 | const boost::filesystem::path& GetPath() const 60 | { 61 | return path_; 62 | } 63 | 64 | virtual void Start(); 65 | 66 | virtual void Stop(); 67 | }; 68 | } 69 | -------------------------------------------------------------------------------- /Framework/Filters/IMSTSourceFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #if !defined(ATOMIT_ENABLE_IMST_GATEWAY) 35 | # error The macro ATOMIT_ENABLE_IMST_GATEWAY must be defined to use this file 36 | #endif 37 | 38 | #if ATOMIT_ENABLE_IMST_GATEWAY == 1 39 | 40 | #include "SourceFilter.h" 41 | 42 | namespace AtomIT 43 | { 44 | class IMSTSourceFilter : public SourceFilter 45 | { 46 | private: 47 | std::string metadata_; 48 | 49 | protected: 50 | virtual FetchStatus Fetch(Message& message); 51 | 52 | public: 53 | IMSTSourceFilter(const std::string& name, 54 | ITimeSeriesManager& manager, 55 | const std::string& timeSeries); 56 | 57 | virtual ~IMSTSourceFilter(); 58 | 59 | void SetMetadata(const std::string& metadata) 60 | { 61 | metadata_ = metadata; 62 | } 63 | 64 | const std::string& GetMetadata() const 65 | { 66 | return metadata_; 67 | } 68 | 69 | virtual void Start(); 70 | 71 | virtual void Stop(); 72 | }; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /Framework/Filters/DemultiplexerFilter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "DemultiplexerFilter.h" 33 | 34 | #include 35 | 36 | namespace AtomIT 37 | { 38 | AdapterFilter::PushStatus DemultiplexerFilter::Push(const Message& message) 39 | { 40 | ConvertedMessages outputs; 41 | 42 | Demux(outputs, message); 43 | 44 | for (ConvertedMessages::const_iterator it = outputs.begin(); 45 | it != outputs.end(); ++it) 46 | { 47 | TimeSeriesWriter writer(manager_, it->first); 48 | 49 | if (!writer.Append(it->second)) 50 | { 51 | LOG(ERROR) << "Cannot demux message to time series: " << it->first; 52 | } 53 | } 54 | 55 | return PushStatus_Success; 56 | } 57 | 58 | 59 | DemultiplexerFilter::DemultiplexerFilter(const std::string& name, 60 | ITimeSeriesManager& manager, 61 | const std::string& inputTimeSeries) : 62 | AdapterFilter(name, manager, inputTimeSeries), 63 | manager_(manager) 64 | { 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Framework/FileWritersPool.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "AtomITToolbox.h" 35 | 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | class FileWritersPool : public boost::noncopyable 41 | { 42 | private: 43 | class ActiveWriter; 44 | 45 | typedef std::map< boost::filesystem::path, 46 | boost::shared_ptr > ActiveWriters; 47 | 48 | boost::mutex poolMutex_; 49 | ActiveWriters writers_; 50 | 51 | public: 52 | class Accessor : public boost::noncopyable 53 | { 54 | private: 55 | FileWritersPool& pool_; 56 | boost::filesystem::path path_; 57 | boost::shared_ptr writer_; 58 | 59 | public: 60 | Accessor(FileWritersPool& pool, 61 | const boost::filesystem::path& path, 62 | bool append, 63 | bool binary, 64 | const std::string& header); 65 | 66 | ~Accessor(); 67 | 68 | void Write(const std::string& buffer); 69 | }; 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /Framework/TimeSeries/ITimeSeriesAccessor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "../AtomITEnumerations.h" 35 | #include "ITimeSeriesBackend.h" 36 | 37 | namespace AtomIT 38 | { 39 | class ITimeSeriesAccessor : public boost::noncopyable 40 | { 41 | public: 42 | class ILock : public boost::noncopyable 43 | { 44 | public: 45 | virtual ~ILock() 46 | { 47 | } 48 | 49 | // Might be "false" if the series was deleted after the accessor 50 | // was created 51 | virtual bool HasBackend() const = 0; 52 | 53 | // The caller must ensure that "HasBackend()" returns "true" 54 | virtual ITimeSeriesBackend& GetBackend() = 0; 55 | 56 | virtual void NotifyModification() = 0; 57 | 58 | virtual TimestampType GetDefaultTimestampType() const = 0; 59 | }; 60 | 61 | virtual ~ITimeSeriesAccessor() 62 | { 63 | } 64 | 65 | virtual ILock* Lock() = 0; 66 | 67 | // Wait for some modification until the given timeout 68 | virtual bool WaitModification(unsigned int milliseconds) = 0; 69 | }; 70 | } 71 | -------------------------------------------------------------------------------- /Applications/AtomITRestApi.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "ServerContext.h" 35 | 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | class AtomITRestApi : public Orthanc::RestApi 41 | { 42 | private: 43 | ServerContext& serverContext_; 44 | 45 | static ITimeSeriesManager& GetManager(Orthanc::RestApiCall& call); 46 | 47 | static void ServeRoot(Orthanc::RestApiGetCall& call); 48 | 49 | static void ListTimeSeries(Orthanc::RestApiGetCall& call); 50 | 51 | static void GetTimeSeriesContent(Orthanc::RestApiGetCall& call); 52 | 53 | static void GetRawValue(Orthanc::RestApiGetCall& call); 54 | 55 | static void DeleteTimestamp(Orthanc::RestApiDeleteCall& call); 56 | 57 | static void DeleteContent(Orthanc::RestApiDeleteCall& call); 58 | 59 | template 60 | static void AppendMessage(Call& call); 61 | 62 | static void GetTimeSeriesStatistics(Orthanc::RestApiGetCall& call); 63 | 64 | public: 65 | explicit AtomITRestApi(ServerContext& serverContext); 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /Framework/Filters/FileLinesSourceFilter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "FileLinesSourceFilter.h" 33 | 34 | #include 35 | 36 | namespace AtomIT 37 | { 38 | SourceFilter::FetchStatus 39 | FileLinesSourceFilter::ReadMessage(Message& message, 40 | boost::filesystem::ifstream& stream) 41 | { 42 | std::string s; 43 | 44 | if (std::getline(stream, s)) 45 | { 46 | message.SetMetadata(metadata_); 47 | message.SetValue(Orthanc::Toolbox::StripSpaces(s)); 48 | return FetchStatus_Success; 49 | } 50 | else 51 | { 52 | return FetchStatus_Done; 53 | } 54 | } 55 | 56 | 57 | FileLinesSourceFilter::FileLinesSourceFilter(const std::string& name, 58 | ITimeSeriesManager& manager, 59 | const std::string& timeSeries, 60 | const boost::filesystem::path& path) : 61 | FileReaderFilter(name, manager, timeSeries, path), 62 | metadata_("text/plain") 63 | { 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Framework/TimeSeries/ITimeSeriesManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "ITimeSeriesAccessor.h" 35 | #include "ITimeSeriesObserver.h" 36 | #include "../AtomITEnumerations.h" 37 | 38 | #include 39 | 40 | namespace AtomIT 41 | { 42 | class ITimeSeriesManager : public boost::noncopyable 43 | { 44 | public: 45 | virtual ~ITimeSeriesManager() 46 | { 47 | } 48 | 49 | virtual void Register(ITimeSeriesObserver& observer, 50 | const std::string& timeSeries) = 0; 51 | 52 | virtual void Unregister(ITimeSeriesObserver& observer, 53 | const std::string& timeSeries) = 0; 54 | 55 | virtual void ListTimeSeries(std::set& target) = 0; 56 | 57 | virtual void CreateTimeSeries(const std::string& name, 58 | TimestampType defaultType) = 0; 59 | 60 | virtual void DeleteTimeSeries(const std::string& name) = 0; 61 | 62 | virtual ITimeSeriesAccessor* CreateAccessor(const std::string& name, 63 | bool hasSynchronousWait) = 0; 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /Framework/Filters/CounterSourceFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "SourceFilter.h" 35 | 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | class CounterSourceFilter : public SourceFilter 41 | { 42 | private: 43 | std::string metadata_; 44 | int64_t counter_; 45 | int64_t stop_; 46 | unsigned int increment_; 47 | 48 | boost::posix_time::time_duration delay_; 49 | 50 | protected: 51 | virtual FetchStatus Fetch(Message& message); 52 | 53 | public: 54 | CounterSourceFilter(const std::string& name, 55 | ITimeSeriesManager& manager, 56 | const std::string& timeSeries); 57 | 58 | void SetMetadata(const std::string& metadata) 59 | { 60 | metadata_ = metadata; 61 | } 62 | 63 | const std::string& GetMetadata() const 64 | { 65 | return metadata_; 66 | } 67 | 68 | void SetRange(int64_t start, 69 | int64_t stop); 70 | 71 | void SetIncrement(unsigned int increment); 72 | 73 | void SetDelay(unsigned int milliseconds); 74 | }; 75 | } 76 | -------------------------------------------------------------------------------- /Framework/Filters/CSVFileSinkFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "SharedFileSinkFilter.h" 35 | 36 | namespace AtomIT 37 | { 38 | class CSVFileSinkFilter : public SharedFileSinkFilter 39 | { 40 | private: 41 | bool addHeader_; 42 | bool base64_; 43 | 44 | protected: 45 | virtual void GetHeader(std::string& header); 46 | 47 | virtual bool Encode(std::string& result, 48 | const std::string& inputTimeSeries, 49 | const Message& message); 50 | 51 | public: 52 | CSVFileSinkFilter(const std::string& name, 53 | ITimeSeriesManager& manager, 54 | const std::string& timeSeries, 55 | FileWritersPool& pool, 56 | const boost::filesystem::path& path); 57 | 58 | void SetHeaderAdded(bool add) 59 | { 60 | addHeader_ = add; 61 | } 62 | 63 | void SetBase64Encoded(bool enable) 64 | { 65 | base64_ = enable; 66 | } 67 | 68 | bool IsHeaderAdded() const 69 | { 70 | return addHeader_; 71 | } 72 | 73 | bool IsBase64Encoded() const 74 | { 75 | return base64_; 76 | } 77 | }; 78 | } 79 | -------------------------------------------------------------------------------- /Framework/MQTT/Broker.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | 37 | #include "../ConfigurationSection.h" 38 | 39 | namespace AtomIT 40 | { 41 | namespace MQTT 42 | { 43 | class Broker 44 | { 45 | private: 46 | std::string server_; 47 | uint16_t port_; 48 | std::string username_; 49 | std::string password_; 50 | 51 | public: 52 | Broker(); 53 | 54 | const std::string& GetServer() const 55 | { 56 | return server_; 57 | } 58 | 59 | uint16_t GetPort() const 60 | { 61 | return port_; 62 | } 63 | 64 | bool HasCredentials() const; 65 | 66 | const std::string& GetUsername() const; 67 | 68 | const std::string& GetPassword() const; 69 | 70 | void SetServer(const std::string& server) 71 | { 72 | server_ = server; 73 | } 74 | 75 | void SetPort(uint16_t port); 76 | 77 | void ClearCredentials(); 78 | 79 | void SetCredentials(const std::string& username, 80 | const std::string& password); 81 | 82 | static Broker Parse(const ConfigurationSection& config); 83 | }; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Framework/Filters/HttpPostSinkFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "AdapterFilter.h" 35 | 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | class HttpPostSinkFilter : public AdapterFilter 41 | { 42 | private: 43 | Orthanc::HttpClient client_; 44 | 45 | protected: 46 | virtual PushStatus Push(const Message& message); 47 | 48 | public: 49 | HttpPostSinkFilter(const std::string& name, 50 | ITimeSeriesManager& manager, 51 | const std::string& timeSeries, 52 | const std::string& url); 53 | 54 | void SetUrl(const std::string& url) 55 | { 56 | client_.SetUrl(url); 57 | } 58 | 59 | const std::string& GetUrl() const 60 | { 61 | return client_.GetUrl(); 62 | } 63 | 64 | void SetTimeout(long seconds) 65 | { 66 | client_.SetTimeout(seconds); 67 | } 68 | 69 | long GetTimeout() const 70 | { 71 | return client_.GetTimeout(); 72 | } 73 | 74 | void SetCredentials(const char* username, 75 | const char* password) 76 | { 77 | client_.SetCredentials(username, password); 78 | } 79 | }; 80 | } 81 | -------------------------------------------------------------------------------- /Framework/MQTT/SynchronousClient.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "Broker.h" 35 | 36 | #include 37 | #include 38 | 39 | namespace AtomIT 40 | { 41 | namespace MQTT 42 | { 43 | class SynchronousClient : public boost::noncopyable 44 | { 45 | private: 46 | class StringHolder; 47 | class ReceivedMessageHolder; 48 | class PImpl; 49 | 50 | PImpl *pimpl_; 51 | 52 | public: 53 | static void GlobalInitialization(bool useSsl); 54 | 55 | SynchronousClient(); 56 | 57 | ~SynchronousClient(); 58 | 59 | bool IsConnected() const; 60 | 61 | void Connect(const Broker& broker, 62 | const std::string& clientId); 63 | 64 | void Disconnect(); 65 | 66 | void Subscribe(const std::vector& topics); 67 | 68 | bool Receive(std::string& topic, 69 | std::string& message, 70 | unsigned int timeout /* in milliseconds */); 71 | 72 | void PublishPending(); 73 | 74 | bool Publish(const std::string& topic, 75 | const std::string& message, 76 | unsigned int timeout /* in milliseconds */); 77 | }; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Framework/TimeSeries/TimeSeriesWriter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "ITimeSeriesManager.h" 35 | #include "../Message.h" 36 | 37 | #include 38 | 39 | namespace AtomIT 40 | { 41 | class TimeSeriesWriter : public boost::noncopyable 42 | { 43 | private: 44 | std::auto_ptr accessor_; 45 | 46 | public: 47 | class Transaction : public boost::noncopyable 48 | { 49 | private: 50 | std::auto_ptr lock_; 51 | std::auto_ptr transaction_; 52 | bool modified_; 53 | 54 | public: 55 | explicit Transaction(TimeSeriesWriter& writer); 56 | 57 | virtual ~Transaction(); 58 | 59 | bool GetLastTimestamp(int64_t& timestamp) const; 60 | 61 | bool Append(int64_t timestamp, 62 | const std::string& metadata, 63 | const std::string& value); 64 | 65 | bool DeleteRange(int64_t start, 66 | int64_t end); 67 | 68 | void ClearContent(); 69 | 70 | TimestampType GetDefaultTimestampType() const; 71 | }; 72 | 73 | 74 | TimeSeriesWriter(ITimeSeriesManager& manager, 75 | const std::string& name); 76 | 77 | bool Append(const Message& message); 78 | }; 79 | } 80 | -------------------------------------------------------------------------------- /Framework/Message.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "AtomITEnumerations.h" 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace AtomIT 41 | { 42 | class Message 43 | { 44 | private: 45 | TimestampType type_; 46 | int64_t timestamp_; 47 | std::string metadata_; 48 | std::string value_; 49 | 50 | public: 51 | Message(); 52 | 53 | void SetTimestampType(TimestampType type); 54 | 55 | TimestampType GetTimestampType() const 56 | { 57 | return type_; 58 | } 59 | 60 | int64_t GetTimestamp() const; 61 | 62 | void SetTimestamp(int64_t timestamp); 63 | 64 | const std::string& GetMetadata() const 65 | { 66 | return metadata_; 67 | } 68 | 69 | void SetMetadata(const std::string& metadata) 70 | { 71 | metadata_ = metadata; 72 | } 73 | 74 | void SwapMetadata(std::string& metadata) 75 | { 76 | metadata_.swap(metadata); 77 | } 78 | 79 | const std::string& GetValue() const 80 | { 81 | return value_; 82 | } 83 | 84 | void SetValue(const std::string& value) 85 | { 86 | value_ = value; 87 | } 88 | 89 | void SwapValue(std::string& value) 90 | { 91 | value_.swap(value); 92 | } 93 | 94 | std::string FormatValue() const; 95 | 96 | void Format(Json::Value& result) const; 97 | }; 98 | } 99 | -------------------------------------------------------------------------------- /Resources/ThirdParty/tiny-AES-c-master/README.md: -------------------------------------------------------------------------------- 1 | ### Tiny AES in C 2 | 3 | This is a small and portable implementation of the AES ECB and CBC encryption algorithms written in C. 4 | 5 | You can override the default block-size of 128 bit with 192 or 256 bit by defining the symbols AES192 or AES256 in `aes.h`. 6 | 7 | The API is very simple and looks like this (I am using C99 ``-style annotated types): 8 | 9 | ```C 10 | void AES_ECB_encrypt(uint8_t* input, const uint8_t* key, uint8_t* output); 11 | void AES_ECB_decrypt(uint8_t* input, const uint8_t* key, uint8_t* output); 12 | void AES_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 13 | void AES_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 14 | ``` 15 | 16 | 17 | You can choose to use one or both of the modes-of-operation, by defining the symbols CBC and ECB. See the header file for clarification. 18 | 19 | There is no built-in error checking or protection from out-of-bounds memory access errors as a result of malicious input. The two functions AES_ECB_xxcrypt() do most of the work, and they expect inputs of 128 bit length. 20 | 21 | The module uses less than 200 bytes of RAM and 2.3K ROM when compiled for ARM (<2K for Thumb but YMMV). 22 | 23 | It is one of the smallest implementation in C I've seen yet, but do contact me if you know of something smaller (or have improvements to the code here). 24 | 25 | I've successfully used the code on 64bit x86, 32bit ARM and 8 bit AVR platforms. 26 | 27 | GCC size output when only ECB mode is compiled for ARM (using 128 bit block size): 28 | 29 | $ arm-none-eabi-gcc -Os -c aes.c -DCBC=0 30 | $ size aes.o 31 | text data bss dec hex filename 32 | 2071 0 184 2255 8cf aes.o 33 | 34 | 35 | .. and when compiling for the THUMB instruction set, we end up just above 1.7K in code size. 36 | 37 | $ arm-none-eabi-gcc -mthumb -Os -c aes.c -DCBC=0 38 | $ size aes.o 39 | text data bss dec hex filename 40 | 1551 0 184 1735 6c7 aes.o 41 | 42 | 43 | 44 | 45 | I am using the Free Software Foundation, ARM GCC compiler: 46 | 47 | $ arm-none-eabi-gcc --version 48 | arm-none-eabi-gcc (4.8.4-1+11-1) 4.8.4 20141219 (release) 49 | Copyright (C) 2013 Free Software Foundation, Inc. 50 | This is free software; see the source for copying conditions. There is NO 51 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 52 | 53 | 54 | 55 | This implementation is verified against the data in: 56 | 57 | [National Institute of Standards and Technology Special Publication 800-38A 2001 ED](http://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf) Appendix F: Example Vectors for Modes of Operation of the AES. 58 | 59 | 60 | A heartfelt thank-you to all the nice people out there who have contributed to this project. 61 | 62 | 63 | All material in this repository is in the public domain. 64 | -------------------------------------------------------------------------------- /Framework/Filters/HttpPostSinkFilter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "HttpPostSinkFilter.h" 33 | 34 | #include 35 | 36 | namespace AtomIT 37 | { 38 | AdapterFilter::PushStatus HttpPostSinkFilter::Push(const Message& message) 39 | { 40 | std::string mime = "application/octet-stream"; 41 | 42 | if (Orthanc::Toolbox::IsAsciiString(mime.c_str(), mime.size())) 43 | { 44 | std::vector tokens; 45 | Orthanc::Toolbox::TokenizeString(tokens, message.GetMetadata(), '/'); 46 | if (tokens.size() == 2) 47 | { 48 | mime = message.GetMetadata(); 49 | } 50 | } 51 | 52 | client_.ClearHeaders(); 53 | client_.AddHeader("Content-Type", mime); 54 | client_.SetBody(message.GetValue()); 55 | 56 | std::string answer; 57 | if (client_.Apply(answer)) 58 | { 59 | return PushStatus_Success; 60 | } 61 | else 62 | { 63 | return PushStatus_Failure; 64 | } 65 | } 66 | 67 | 68 | HttpPostSinkFilter::HttpPostSinkFilter(const std::string& name, 69 | ITimeSeriesManager& manager, 70 | const std::string& timeSeries, 71 | const std::string& url) : 72 | AdapterFilter(name, manager, timeSeries) 73 | { 74 | client_.SetMethod(Orthanc::HttpMethod_Post); 75 | client_.SetRedirectionFollowed(true); 76 | client_.SetUrl(url); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Resources/Orthanc/LinuxStandardBaseToolchain.cmake: -------------------------------------------------------------------------------- 1 | # LSB_CC=gcc-4.8 LSB_CXX=g++-4.8 cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../Resources/LinuxStandardBaseToolchain.cmake -DUSE_LEGACY_JSONCPP=ON 2 | 3 | INCLUDE(CMakeForceCompiler) 4 | 5 | SET(LSB_PATH $ENV{LSB_PATH}) 6 | SET(LSB_CC $ENV{LSB_CC}) 7 | SET(LSB_CXX $ENV{LSB_CXX}) 8 | SET(LSB_TARGET_VERSION "4.0") 9 | 10 | IF ("${LSB_PATH}" STREQUAL "") 11 | SET(LSB_PATH "/opt/lsb") 12 | ENDIF() 13 | 14 | IF (EXISTS ${LSB_PATH}/lib64) 15 | SET(LSB_TARGET_PROCESSOR "x86_64") 16 | SET(LSB_LIBPATH ${LSB_PATH}/lib64-${LSB_TARGET_VERSION}) 17 | ELSEIF (EXISTS ${LSB_PATH}/lib) 18 | SET(LSB_TARGET_PROCESSOR "x86") 19 | SET(LSB_LIBPATH ${LSB_PATH}/lib-${LSB_TARGET_VERSION}) 20 | ELSE() 21 | MESSAGE(FATAL_ERROR "Unable to detect the target processor architecture. Check the LSB_PATH environment variable.") 22 | ENDIF() 23 | 24 | SET(LSB_CPPPATH ${LSB_PATH}/include) 25 | SET(PKG_CONFIG_PATH ${LSB_LIBPATH}/pkgconfig/) 26 | 27 | # the name of the target operating system 28 | SET(CMAKE_SYSTEM_NAME Linux) 29 | SET(CMAKE_SYSTEM_VERSION LinuxStandardBase) 30 | SET(CMAKE_SYSTEM_PROCESSOR ${LSB_TARGET_PROCESSOR}) 31 | 32 | # which compilers to use for C and C++ 33 | SET(CMAKE_C_COMPILER ${LSB_PATH}/bin/lsbcc) 34 | CMAKE_FORCE_CXX_COMPILER(${LSB_PATH}/bin/lsbc++ GNU) 35 | 36 | # here is the target environment located 37 | SET(CMAKE_FIND_ROOT_PATH ${LSB_PATH}) 38 | 39 | # adjust the default behaviour of the FIND_XXX() commands: 40 | # search headers and libraries in the target environment, search 41 | # programs in the host environment 42 | SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 43 | SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER) 44 | SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER) 45 | 46 | SET(CMAKE_CROSSCOMPILING OFF) 47 | 48 | 49 | SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -I${LSB_PATH}/include" CACHE INTERNAL "" FORCE) 50 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -nostdinc++ -I${LSB_PATH}/include -I${LSB_PATH}/include/c++ -I${LSB_PATH}/include/c++/backward" CACHE INTERNAL "" FORCE) 51 | SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH} --lsb-besteffort" CACHE INTERNAL "" FORCE) 52 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-target-version=${LSB_TARGET_VERSION} -L${LSB_LIBPATH} --lsb-besteffort" CACHE INTERNAL "" FORCE) 53 | 54 | if (NOT "${LSB_CXX}" STREQUAL "") 55 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-cxx=${LSB_CXX}") 56 | SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-cxx=${LSB_CXX}") 57 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-cxx=${LSB_CXX}") 58 | endif() 59 | 60 | if (NOT "${LSB_CC}" STREQUAL "") 61 | SET(CMAKE_C_FLAGS "${CMAKE_CC_FLAGS} --lsb-cc=${LSB_CC}") 62 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --lsb-cc=${LSB_CC}") 63 | SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --lsb-cc=${LSB_CC}") 64 | SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --lsb-cc=${LSB_CC}") 65 | endif() 66 | 67 | -------------------------------------------------------------------------------- /Framework/Filters/MQTTSinkFilter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "MQTTSinkFilter.h" 33 | 34 | #include 35 | 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | AdapterFilter::PushStatus MQTTSinkFilter::Push(const Message& message) 41 | { 42 | MQTT::MQTTClientWrapper::Accessor accessor(client_); 43 | 44 | if (accessor.IsConnected()) 45 | { 46 | LOG(INFO) << "MQTT message sent by filter " << GetName() << ": \"" 47 | << message.FormatValue() << "\" (topic " << message.GetMetadata() << ")"; 48 | accessor.GetClient().Publish(message.GetMetadata(), message.GetValue(), 100); 49 | return PushStatus_Success; 50 | } 51 | else 52 | { 53 | // Failure during the connection attempt: Wait 1s before 54 | // trying reconnecting 55 | boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); 56 | return PushStatus_Retry; 57 | } 58 | } 59 | 60 | 61 | MQTTSinkFilter::MQTTSinkFilter(const std::string& name, 62 | ITimeSeriesManager& manager, 63 | const std::string& timeSeries) : 64 | AdapterFilter(name, manager, timeSeries), 65 | client_("AtomIT-" + name) 66 | { 67 | } 68 | 69 | 70 | void MQTTSinkFilter::Start() 71 | { 72 | client_.Start(); 73 | AdapterFilter::Start(); 74 | } 75 | 76 | 77 | void MQTTSinkFilter::Stop() 78 | { 79 | AdapterFilter::Stop(); 80 | client_.Stop(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Framework/Filters/MQTTSourceFilter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "MQTTSourceFilter.h" 33 | 34 | #include 35 | 36 | namespace AtomIT 37 | { 38 | SourceFilter::FetchStatus MQTTSourceFilter::Fetch(Message& message) 39 | { 40 | MQTT::MQTTClientWrapper::Accessor accessor(client_); 41 | 42 | if (accessor.IsConnected()) 43 | { 44 | std::string topic, value; 45 | 46 | if (accessor.GetClient().Receive(topic, value, 100)) 47 | { 48 | message.SwapMetadata(topic); 49 | message.SwapValue(value); 50 | return FetchStatus_Success; 51 | } 52 | else 53 | { 54 | return FetchStatus_Invalid; 55 | } 56 | } 57 | else 58 | { 59 | // Failure during the connection attempt: Wait 1s before 60 | // trying reconnecting 61 | boost::this_thread::sleep(boost::posix_time::milliseconds(1000)); 62 | return FetchStatus_Invalid; 63 | } 64 | } 65 | 66 | 67 | MQTTSourceFilter::MQTTSourceFilter(const std::string& name, 68 | ITimeSeriesManager& manager, 69 | const std::string& timeSeries) : 70 | SourceFilter(name, manager, timeSeries), 71 | client_("AtomIT-" + name) 72 | { 73 | } 74 | 75 | 76 | void MQTTSourceFilter::Start() 77 | { 78 | client_.Start(); 79 | SourceFilter::Start(); 80 | } 81 | 82 | 83 | void MQTTSourceFilter::Stop() 84 | { 85 | SourceFilter::Stop(); 86 | client_.Stop(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Applications/ServerContext.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "../Framework/FileWritersPool.h" 35 | #include "../Framework/Filters/IFilter.h" 36 | #include "../Framework/TimeSeries/ITimeSeriesManager.h" 37 | 38 | #include 39 | 40 | namespace AtomIT 41 | { 42 | class ServerContext : public boost::noncopyable 43 | { 44 | private: 45 | enum State 46 | { 47 | State_Setup, 48 | State_Running, 49 | State_Done 50 | }; 51 | 52 | typedef std::list Filters; 53 | 54 | boost::mutex mutex_; 55 | bool continue_; 56 | State state_; 57 | ITimeSeriesManager& manager_; 58 | Filters filters_; 59 | std::vector threads_; 60 | FileWritersPool pool_; 61 | 62 | static bool StartFilter(IFilter& filter); 63 | 64 | static bool StopFilter(IFilter& filter); 65 | 66 | static void WorkerThread(bool* continue_, 67 | IFilter* filter); 68 | 69 | bool StopInternal(); 70 | 71 | public: 72 | explicit ServerContext(ITimeSeriesManager& manager); 73 | 74 | ~ServerContext(); 75 | 76 | ITimeSeriesManager& GetManager() 77 | { 78 | return manager_; 79 | } 80 | 81 | FileWritersPool& GetFileWritersPool() 82 | { 83 | return pool_; 84 | } 85 | 86 | void AddFilter(IFilter* filter); 87 | 88 | void Start(); 89 | 90 | void Stop(); 91 | }; 92 | } 93 | -------------------------------------------------------------------------------- /Framework/TimeSeries/TimeSeriesReader.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "ITimeSeriesManager.h" 35 | 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | class TimeSeriesReader : public boost::noncopyable 41 | { 42 | private: 43 | std::auto_ptr accessor_; 44 | 45 | public: 46 | class Transaction : public boost::noncopyable 47 | { 48 | private: 49 | std::auto_ptr lock_; 50 | std::auto_ptr transaction_; 51 | bool valid_; 52 | int64_t timestamp_; 53 | 54 | public: 55 | explicit Transaction(TimeSeriesReader& reader); 56 | 57 | bool IsValid() const 58 | { 59 | return valid_; 60 | } 61 | 62 | bool GetTimestamp(int64_t& result) const; 63 | 64 | bool SeekFirst(); 65 | 66 | bool SeekLast(); 67 | 68 | void Seek(int64_t timestamp); 69 | 70 | bool SeekNearest(int64_t timestamp); 71 | 72 | bool SeekNext(); 73 | 74 | bool SeekPrevious(); 75 | 76 | bool Read(std::string& metadata, 77 | std::string& value); 78 | 79 | void GetStatistics(uint64_t& length, 80 | uint64_t& size); 81 | }; 82 | 83 | 84 | TimeSeriesReader(ITimeSeriesManager& manager, 85 | const std::string& name, 86 | bool hasSynchronousWait); 87 | 88 | bool WaitModification(unsigned int milliseconds); 89 | }; 90 | } 91 | -------------------------------------------------------------------------------- /Framework/Filters/LuaFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "DemultiplexerFilter.h" 35 | 36 | #include 37 | 38 | #include 39 | 40 | namespace AtomIT 41 | { 42 | class LuaFilter : public DemultiplexerFilter 43 | { 44 | private: 45 | class OutputParser; 46 | 47 | std::string defaultTimeSeries_; 48 | Orthanc::LuaContext lua_; 49 | 50 | static int ApplyStringConverter(lua_State *state, 51 | void (*func) (std::string&, const std::string&), 52 | const char* name); 53 | 54 | static int LuaDecodeBase64(lua_State *state); 55 | 56 | static int LuaEncodeBase64(lua_State *state); 57 | 58 | static int LuaParseHexadecimal(lua_State *state); 59 | 60 | static void FormatHexadecimalUpper(std::string& target, 61 | const std::string& source); 62 | 63 | static int LuaFormatHexadecimal(lua_State *state); 64 | 65 | static int ParseXml(lua_State *state); 66 | 67 | protected: 68 | virtual void Demux(ConvertedMessages& outputs, 69 | const Message& source); 70 | 71 | public: 72 | LuaFilter(const std::string& name, 73 | ITimeSeriesManager& manager, 74 | const std::string& inputTimeSeries); 75 | 76 | void ExecuteFile(const boost::filesystem::path& path); 77 | 78 | void SetDefaultOutputTimeSeries(const std::string& timeSeries) 79 | { 80 | defaultTimeSeries_ = timeSeries; 81 | } 82 | }; 83 | } 84 | -------------------------------------------------------------------------------- /Framework/Filters/SharedFileSinkFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "AdapterFilter.h" 35 | #include "../FileWritersPool.h" 36 | 37 | namespace AtomIT 38 | { 39 | class SharedFileSinkFilter : public AdapterFilter 40 | { 41 | private: 42 | FileWritersPool& pool_; 43 | std::auto_ptr writer_; 44 | boost::filesystem::path path_; 45 | bool append_; 46 | bool binary_; 47 | 48 | protected: 49 | virtual void GetHeader(std::string& result) = 0; 50 | 51 | virtual bool Encode(std::string& result, 52 | const std::string& inputTimeSeries, 53 | const Message& message) = 0; 54 | 55 | virtual PushStatus Push(const Message& message); 56 | 57 | public: 58 | SharedFileSinkFilter(const std::string& name, 59 | ITimeSeriesManager& manager, 60 | const std::string& timeSeries, 61 | FileWritersPool& pool, 62 | const boost::filesystem::path& path); 63 | 64 | void SetAppend(bool append) 65 | { 66 | append_ = append; 67 | } 68 | 69 | bool IsAppend() const 70 | { 71 | return append_; 72 | } 73 | 74 | void SetBinary(bool binary) 75 | { 76 | binary_ = binary; 77 | } 78 | 79 | bool IsBinary() const 80 | { 81 | return binary_; 82 | } 83 | 84 | virtual void Start(); 85 | 86 | virtual void Stop(); 87 | }; 88 | } 89 | -------------------------------------------------------------------------------- /Framework/TimeSeries/SQLiteBackend/SQLiteDatabase.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | class SQLiteDatabase : public boost::noncopyable 41 | { 42 | private: 43 | static void FlushWorker(SQLiteDatabase* that); 44 | 45 | void SetupDatabase(); 46 | 47 | boost::mutex mutex_; 48 | Orthanc::SQLite::Connection connection_; 49 | bool continue_; 50 | boost::thread flushThread_; 51 | 52 | public: 53 | class Transaction : public boost::noncopyable 54 | { 55 | private: 56 | boost::mutex::scoped_lock lock_; 57 | Orthanc::SQLite::Connection& connection_; 58 | std::auto_ptr transaction_; 59 | 60 | public: 61 | explicit Transaction(SQLiteDatabase& database); 62 | 63 | ~Transaction(); 64 | 65 | void Commit(); 66 | 67 | Orthanc::SQLite::Connection& GetConnection() 68 | { 69 | return connection_; 70 | } 71 | 72 | bool HasTimeSeries(const std::string& name); 73 | }; 74 | 75 | 76 | explicit SQLiteDatabase(const std::string& path); 77 | 78 | SQLiteDatabase(); // Create SQLite database in memory 79 | 80 | ~SQLiteDatabase(); 81 | 82 | void DeleteTimeSeries(const std::string& name); 83 | 84 | void CreateTimeSeries(const std::string& name, 85 | uint64_t maxLength, 86 | uint64_t maxSize); 87 | }; 88 | } 89 | -------------------------------------------------------------------------------- /Framework/Filters/FileReaderFilter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "FileReaderFilter.h" 33 | 34 | #include 35 | #include 36 | 37 | namespace AtomIT 38 | { 39 | SourceFilter::FetchStatus FileReaderFilter::Fetch(Message& message) 40 | { 41 | FetchStatus status = ReadMessage(message, stream_); 42 | line_ += 1; 43 | 44 | if (status == FetchStatus_Done) 45 | { 46 | LOG(WARNING) << "Filter \"" << GetName() 47 | << "\" has finished reading all lines from file: " << path_; 48 | } 49 | else if (status == FetchStatus_Invalid) 50 | { 51 | LOG(ERROR) << "Cannot decode message at line " << line_ << " of file: " << path_; 52 | } 53 | 54 | return status; 55 | } 56 | 57 | 58 | FileReaderFilter::FileReaderFilter(const std::string& name, 59 | ITimeSeriesManager& manager, 60 | const std::string& timeSeries, 61 | const boost::filesystem::path& path) : 62 | SourceFilter(name, manager, timeSeries), 63 | path_(path), 64 | line_(0) 65 | { 66 | } 67 | 68 | 69 | void FileReaderFilter::Start() 70 | { 71 | stream_.open(path_); 72 | 73 | if (!stream_.is_open()) 74 | { 75 | LOG(ERROR) << "Filter " << GetName() << " cannot open file: " << path_; 76 | throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentFile); 77 | } 78 | 79 | SourceFilter::Start(); 80 | } 81 | 82 | 83 | void FileReaderFilter::Stop() 84 | { 85 | SourceFilter::Stop(); 86 | stream_.close(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /Framework/TimeSeries/GenericTimeSeriesManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "ITimeSeriesFactory.h" 35 | #include "ITimeSeriesManager.h" 36 | 37 | #include 38 | #include 39 | 40 | namespace AtomIT 41 | { 42 | class GenericTimeSeriesManager : public ITimeSeriesManager 43 | { 44 | private: 45 | class TimeSeries; 46 | class Accessor; 47 | class SynchronousAccessor; 48 | 49 | typedef std::map< std::string, boost::shared_ptr > Content; 50 | 51 | boost::mutex mutex_; 52 | Content content_; 53 | std::auto_ptr factory_; 54 | 55 | boost::shared_ptr& GetTimeSeries(const std::string& name); 56 | 57 | public: 58 | explicit GenericTimeSeriesManager(ITimeSeriesFactory* factory); 59 | 60 | virtual ~GenericTimeSeriesManager(); 61 | 62 | virtual void Register(ITimeSeriesObserver& observer, 63 | const std::string& timeSeries); 64 | 65 | virtual void Unregister(ITimeSeriesObserver& observer, 66 | const std::string& timeSeries); 67 | 68 | virtual void ListTimeSeries(std::set& target); 69 | 70 | virtual void CreateTimeSeries(const std::string& name, 71 | TimestampType timestampType); 72 | 73 | virtual void DeleteTimeSeries(const std::string& name); 74 | 75 | virtual ITimeSeriesAccessor* CreateAccessor(const std::string& name, 76 | bool hasSynchronousWait); 77 | }; 78 | } 79 | -------------------------------------------------------------------------------- /Framework/Filters/SharedFileSinkFilter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "SharedFileSinkFilter.h" 33 | 34 | #include 35 | 36 | namespace AtomIT 37 | { 38 | AdapterFilter::PushStatus SharedFileSinkFilter::Push(const Message& message) 39 | { 40 | if (writer_.get() == NULL) 41 | { 42 | throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 43 | } 44 | 45 | std::string encoded; 46 | 47 | if (Encode(encoded, GetInputTimeSeries(), message)) 48 | { 49 | writer_->Write(encoded); 50 | return PushStatus_Success; 51 | } 52 | else 53 | { 54 | return PushStatus_Failure; 55 | } 56 | } 57 | 58 | 59 | SharedFileSinkFilter::SharedFileSinkFilter(const std::string& name, 60 | ITimeSeriesManager& manager, 61 | const std::string& timeSeries, 62 | FileWritersPool& pool, 63 | const boost::filesystem::path& path) : 64 | AdapterFilter(name, manager, timeSeries), 65 | pool_(pool), 66 | path_(path), 67 | append_(false), 68 | binary_(false) 69 | { 70 | } 71 | 72 | 73 | void SharedFileSinkFilter::Start() 74 | { 75 | std::string header; 76 | GetHeader(header); 77 | 78 | writer_.reset(new FileWritersPool::Accessor(pool_, path_, append_, binary_, header)); 79 | 80 | AdapterFilter::Start(); 81 | } 82 | 83 | 84 | void SharedFileSinkFilter::Stop() 85 | { 86 | AdapterFilter::Stop(); 87 | 88 | writer_.reset(NULL); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /Framework/MQTT/MQTTClientWrapper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "SynchronousClient.h" 35 | 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | namespace MQTT 41 | { 42 | class MQTTClientWrapper : public boost::noncopyable 43 | { 44 | private: 45 | std::string clientId_; 46 | Broker broker_; 47 | std::vector topics_; 48 | std::auto_ptr client_; 49 | 50 | bool Connect(); 51 | 52 | public: 53 | explicit MQTTClientWrapper(const std::string& clientId) : 54 | clientId_(clientId) 55 | { 56 | } 57 | 58 | void SetBroker(const Broker& broker) 59 | { 60 | broker_ = broker; 61 | } 62 | 63 | const Broker& GetBroker() const 64 | { 65 | return broker_; 66 | } 67 | 68 | void SetClientId(const std::string& clientId) 69 | { 70 | clientId_ = clientId; 71 | } 72 | 73 | const std::string& GetClientId() const 74 | { 75 | return clientId_; 76 | } 77 | 78 | void AddTopic(const std::string& topic) 79 | { 80 | topics_.push_back(topic); 81 | } 82 | 83 | void Start(); 84 | 85 | void Stop(); 86 | 87 | class Accessor : public boost::noncopyable 88 | { 89 | private: 90 | SynchronousClient *client_; 91 | 92 | public: 93 | explicit Accessor(MQTTClientWrapper& that); 94 | 95 | bool IsConnected() const 96 | { 97 | return client_ != NULL; 98 | } 99 | 100 | SynchronousClient& GetClient() const; 101 | }; 102 | }; 103 | } 104 | } 105 | 106 | -------------------------------------------------------------------------------- /Framework/LoRa/PHYPayload.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "LoRaEnumerations.h" 35 | 36 | #include 37 | #include 38 | 39 | namespace AtomIT 40 | { 41 | namespace LoRa 42 | { 43 | class PHYPayload 44 | { 45 | private: 46 | std::string buffer_; 47 | MessageType type_; 48 | uint8_t mhdr_; 49 | uint8_t rfu_; 50 | uint8_t major_; 51 | uint32_t mic_; 52 | 53 | PHYPayload() 54 | { 55 | } 56 | 57 | void Parse(); 58 | 59 | public: 60 | static PHYPayload ParseHexadecimal(const std::string& message); 61 | 62 | static PHYPayload FromBuffer(const std::string& buffer); 63 | 64 | static PHYPayload FromBuffer(const void* buffer, 65 | size_t size); 66 | 67 | const std::string& GetBuffer() const 68 | { 69 | return buffer_; 70 | } 71 | 72 | MessageType GetMessageType() const 73 | { 74 | return type_; 75 | } 76 | 77 | MessageDirection GetMessageDirection() const 78 | { 79 | return ::AtomIT::LoRa::GetMessageDirection(type_); 80 | } 81 | 82 | uint8_t GetMHDR() const 83 | { 84 | return mhdr_; 85 | } 86 | 87 | uint8_t GetMajor() const 88 | { 89 | return major_; 90 | } 91 | 92 | uint8_t GetRFU() const 93 | { 94 | return rfu_; 95 | } 96 | 97 | uint32_t GetMIC() const 98 | { 99 | return mic_; 100 | } 101 | 102 | bool HasMACPayload() const; 103 | 104 | size_t GetMACPayloadSize() const; 105 | 106 | void GetMACPayload(std::string& result) const; 107 | }; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Framework/Filters/AdapterFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "IFilter.h" 35 | #include "../TimeSeries/TimeSeriesReader.h" 36 | #include "../TimeSeries/TimeSeriesWriter.h" 37 | 38 | #include 39 | 40 | namespace AtomIT 41 | { 42 | // Filter with 1 input and N >= 0 output(s) 43 | class AdapterFilter : public IFilter 44 | { 45 | private: 46 | std::string name_; 47 | ITimeSeriesManager& manager_; 48 | std::string timeSeries_; 49 | TimeSeriesReader reader_; 50 | bool replayHistory_; 51 | bool isValid_; 52 | int64_t timestamp_; 53 | 54 | std::auto_ptr inputPopper_; 55 | 56 | protected: 57 | enum PushStatus 58 | { 59 | PushStatus_Success, 60 | PushStatus_Retry, 61 | PushStatus_Failure 62 | }; 63 | 64 | virtual PushStatus Push(const Message& message) = 0; 65 | 66 | public: 67 | AdapterFilter(const std::string& name, 68 | ITimeSeriesManager& manager, 69 | const std::string& timeSeries); 70 | 71 | void SetReplayHistory(bool replay) 72 | { 73 | replayHistory_ = replay; 74 | } 75 | 76 | bool IsReplayHistory() const 77 | { 78 | return replayHistory_; 79 | } 80 | 81 | const std::string& GetInputTimeSeries() const 82 | { 83 | return timeSeries_; 84 | } 85 | 86 | void SetPopInput(bool pop); 87 | 88 | bool IsPopInput() const; 89 | 90 | virtual std::string GetName() const 91 | { 92 | return name_; 93 | } 94 | 95 | virtual void Start(); 96 | 97 | virtual bool Step(); 98 | 99 | virtual void Stop() 100 | { 101 | } 102 | }; 103 | } 104 | -------------------------------------------------------------------------------- /Framework/TimeSeries/SQLiteBackend/SQLiteTimeSeriesTransaction.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "SQLiteDatabase.h" 35 | 36 | namespace AtomIT 37 | { 38 | class SQLiteTimeSeriesTransaction : public boost::noncopyable 39 | { 40 | private: 41 | SQLiteDatabase::Transaction transaction_; 42 | 43 | int64_t id_; 44 | uint64_t maxLength_; 45 | uint64_t maxSize_; 46 | uint64_t currentLength_; 47 | uint64_t currentSize_; 48 | bool hasLastTimestamp_; 49 | int64_t lastTimestamp_; 50 | 51 | bool SanityCheck(); 52 | 53 | void UpdateTimeSeriesTable(); 54 | 55 | void RemoveOldest(); 56 | 57 | public: 58 | SQLiteTimeSeriesTransaction(SQLiteDatabase& database, 59 | const std::string& name); 60 | 61 | ~SQLiteTimeSeriesTransaction(); 62 | 63 | void DeleteRange(int64_t start, 64 | int64_t end); 65 | 66 | bool SeekFirst(int64_t& result); 67 | 68 | bool SeekLast(int64_t& result); 69 | 70 | bool SeekNearest(int64_t& result, 71 | int64_t timestamp); 72 | 73 | bool SeekNext(int64_t& result, 74 | int64_t timestamp); 75 | 76 | bool SeekPrevious(int64_t& result, 77 | int64_t timestamp); 78 | 79 | bool Read(std::string& metadata, 80 | std::string& value, 81 | int64_t timestamp); 82 | 83 | bool Append(int64_t timestamp, 84 | const std::string& metadata, 85 | const std::string& value); 86 | 87 | void GetStatistics(uint64_t& length, 88 | uint64_t& size); 89 | 90 | void ClearContent(); 91 | 92 | bool GetLastTimestamp(int64_t& result); 93 | 94 | static void UpdateQuota(SQLiteDatabase& database, 95 | const std::string& name); 96 | }; 97 | } 98 | -------------------------------------------------------------------------------- /Framework/TimeSeries/ITimeSeriesBackend.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | class ITimeSeriesBackend : public boost::noncopyable 41 | { 42 | public: 43 | class ITransaction : public boost::noncopyable 44 | { 45 | public: 46 | virtual ~ITransaction() 47 | { 48 | } 49 | 50 | virtual void ClearContent() = 0; 51 | 52 | virtual void DeleteRange(int64_t start, 53 | int64_t end) = 0; 54 | 55 | virtual bool SeekFirst(int64_t& result) = 0; 56 | 57 | virtual bool SeekLast(int64_t& result) = 0; 58 | 59 | // Returns the first timestamp that is after or equal to "timestamp" 60 | virtual bool SeekNearest(int64_t& result, 61 | int64_t timestamp) = 0; 62 | 63 | virtual bool SeekNext(int64_t& result, 64 | int64_t timestamp) = 0; 65 | 66 | virtual bool SeekPrevious(int64_t& result, 67 | int64_t timestamp) = 0; 68 | 69 | virtual bool Read(std::string& metadata, 70 | std::string& value, 71 | int64_t timestamp) = 0; 72 | 73 | // Returns "false" if not enough space, or if "timestamp <= SeekLast()" 74 | virtual bool Append(int64_t timestamp, 75 | const std::string& metadata, 76 | const std::string& value) = 0; 77 | 78 | virtual void GetStatistics(uint64_t& length, 79 | uint64_t& size) = 0; 80 | 81 | virtual bool GetLastTimestamp(int64_t& timestamp) = 0; 82 | }; 83 | 84 | virtual ~ITimeSeriesBackend() 85 | { 86 | } 87 | 88 | virtual ITransaction* CreateTransaction(bool isReadOnly) = 0; 89 | }; 90 | } 91 | -------------------------------------------------------------------------------- /Documentation/SampleIMST.log: -------------------------------------------------------------------------------- 1 | W1222 15:41:42.358151 main.cpp:385] Atom-IT version: mainline (20171222T142446) 2 | W1222 15:41:42.359014 ConfigurationSection.cpp:146] Loading configuration from: "./Configuration.json" 3 | I1222 15:41:42.360475 MainTimeSeriesFactory.cpp:428] Configuring auto-creation of time series with parameters: {} 4 | W1222 15:41:42.367092 MainTimeSeriesFactory.cpp:289] Enabling auto-creation of time series: Memory backend with unlimited length, unlimited size, and sequential timestamps 5 | I1222 15:41:42.367363 FilterFactory.cpp:385] Creating filter with parameters: { 6 | "Output" : "lora", 7 | "Type" : "IMST" 8 | } 9 | W1222 15:41:42.367686 GenericTimeSeriesManager.cpp:307] Auto-creation of time series: lora 10 | I1222 15:41:42.367855 GenericTimeSeriesManager.cpp:80] Time series created: lora 11 | I1222 15:41:42.374872 ServerContext.cpp:187] Adding filter (no name) 12 | I1222 15:41:42.375234 FilterFactory.cpp:385] Creating filter with parameters: { 13 | "Input" : "lora", 14 | "Path" : "lora.csv", 15 | "Type" : "CSVSink" 16 | } 17 | I1222 15:41:42.375916 ServerContext.cpp:187] Adding filter (no name) 18 | W1222 15:41:42.376173 ServerContext.cpp:207] Starting the filters 19 | W1222 15:41:45.270840 IMSTSourceFilter.cpp:279] IMST LoRa concentrator started, packets can now be received 20 | I1222 15:41:45.271177 ServerContext.cpp:44] Filter (no name) has started 21 | I1222 15:41:45.271502 FileWritersPool.cpp:113] Opening file: "lora.csv" 22 | I1222 15:41:45.272700 ServerContext.cpp:44] Filter (no name) has started 23 | W1222 15:41:45.273626 main.cpp:197] The Atom-IT server has started 24 | I1222 15:41:45.277206 MongooseServer.cpp:948] Starting embedded Web server using Mongoose 25 | W1222 15:41:45.294881 main.cpp:153] HTTP server listening on port: 8042 26 | I1222 15:41:46.876706 IMSTSourceFilter.cpp:321] Received one packet from IMST LoRa concentrator 27 | I1222 15:41:46.876995 SourceFilter.cpp:110] Message received by filter (no name): "(binary)" (metadata "application/octet-stream") 28 | ^CW1222 15:41:58.511872 main.cpp:158] HTTP server has stopped 29 | I1222 15:41:58.512194 main.cpp:218] The Atom-IT server is stopping 30 | W1222 15:41:58.512533 ServerContext.cpp:117] Stopping the filters 31 | W1222 15:41:58.895522 IMSTSourceFilter.cpp:369] IMST LoRa concentrator stopped successfully 32 | I1222 15:41:58.895834 ServerContext.cpp:65] Filter (no name) has stopped 33 | I1222 15:41:58.896131 FileWritersPool.cpp:146] Closing file: "lora.csv" 34 | I1222 15:41:58.896837 ServerContext.cpp:65] Filter (no name) has stopped 35 | I1222 15:41:58.897220 GenericTimeSeriesManager.cpp:87] Time series deleted: lora 36 | W1222 15:41:58.897508 main.cpp:443] The Atom-IT server has stopped 37 | 38 | 39 | 40 | 41 | $ cat lora.csv 42 | "lora",0,application/octet-stream,"QWWyFXdbeILfC0aNRZh0TqImSJfS8pyf1kk0CCQkOPQdKKGgdSAwqS9qfpMdGVyIMMBa7keZyWmNwXxflCp3H8kyXbwzPogeJPmUXHEbIax98g6ykypz2D/Ly1CnENDusDDYaoxxR3NgcjYODSjRFYjn855dChBxzHUcNHZlf++z732tLz2sFEaiPph5GiXyBK9iRQ==" 43 | "lora",1,application/octet-stream,"wGWP5c7N/O4bVz4cuDhx4jl9vsI/rlbmkTGsSCTNYYNJiZs3xHZ2oa+Dpy5Wcjj4qkjnFLJ2BR/KuS/YoivJLrYlkHZYEMNNlGVUFRgtSBosLGWHa7f4QAfZW5/B/yuMoQ==" 44 | "lora",2,application/octet-stream,"rAtTc2frYvKPMy81vf5qMtqFmLvpiWo9RpMN7gN1FvTfqgUxNKjHmgW1P3AxLHtuQxg=" 45 | "lora",3,application/octet-stream,"pHl/GX1Gs4jPX5szhXKSsLndIqWtLHWOAfspmwXnAXM6MDqjFZMhEpfWYwr/o4n0XmzIrejJtuGwbQe86PClt03FWNLvokyPRIwkwZ1HEd9TsbIIoCqH4CmkRW6o/ToY4PEb9YemnLVJ3aGa8H3fmUnE/gzq96rcpNEGT4StMeQd/PgSfhUdQWeZk776yA0mqu/zlgk=" 46 | "lora",4,application/octet-stream,"K6Ba6TTEjg==" 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Atom-IT](Resources/AtomITLogoDocumentation.png "Atom-IT") 2 | 3 | The **Atom-IT server** is a lightweight, cross-platform, RESTful 4 | [microservice](https://en.wikipedia.org/wiki/Microservices) for 5 | [Internet of Things](https://en.wikipedia.org/wiki/Internet_of_things) 6 | (IoT) applications. 7 | 8 | Features 9 | -------- 10 | 11 | The Atom-IT server provides a simple framework to define IoT workflows 12 | through configuration files. Its small footprint makes it usable on 13 | most hardware architectures, from the Raspberry Pi to cloud 14 | systems. Its simplicity also makes it a valuable candidate to showcase 15 | IoT networks as a vendor-neutral pedagogical platform. 16 | 17 | The software comes out-of-the-box with the following features: 18 | 19 | * Centralization of time series coming from multiple data sources 20 | and different network protocols. 21 | * Built-in Web server that can be used to receive messages from 22 | callbacks provided by professional IoT networks (such as Sigfox and 23 | Proximus MyThings). 24 | * [Lua scripting](https://en.wikipedia.org/wiki/Lua_(programming_language)) 25 | to transcode packets. 26 | * Support of the [MQTT protocol](https://en.wikipedia.org/wiki/MQTT), both as 27 | publisher and subscriber, which can be used to receive messages 28 | from [The Things Network](https://www.thethingsnetwork.org/) broker. 29 | * Support of the 30 | [IMST iC880A board](https://wireless-solutions.de/products/radiomodules/ic880a.html) 31 | to setup standalone [LoRa](https://www.lora-alliance.org/) gateways 32 | with a [Raspberry Pi](https://www.raspberrypi.org/). 33 | * Decoding of LoRa packets. 34 | * HTTP POST client in order to transmit messages to other IoT 35 | systems. 36 | * Built-in [REST API](Documentation/RestApi.md) that can be used to 37 | drive the server from external heavyweight software, from scripts, 38 | or from Web applications. 39 | * Export and import to/from files (notably in the 40 | [CSV file format](https://en.wikipedia.org/wiki/Comma-separated_values)). 41 | * Long-term storage of messages within [SQLite](https://www.sqlite.org/) databases. 42 | 43 | The server also features a simple Web interface in order to explore 44 | the content of its database. 45 | 46 | 47 | Documentation 48 | ------------- 49 | 50 | * [Quick Start](Documentation/QuickStart.md) 51 | * Usage: 52 | * [Compilation](Documentation/Compilation.md) 53 | * [Basic concepts](Documentation/Concepts.md) 54 | * [Configuration](Documentation/Configuration.md) 55 | * [Available filters](Documentation/Filters.md) 56 | * [Lua scripting](Documentation/Lua.md) 57 | * [REST API](Documentation/RestApi.md) 58 | * Samples of IoT workflow: 59 | * [Connecting to Proximus MyThings](Documentation/SampleProximusMyThings.md) 60 | * [Connecting to Sigfox](Documentation/SampleSigfox.md) 61 | * [Connecting to The Things Network](Documentation/SampleTheThingsNetwork.md) 62 | * [Standalone LoRa gateway](Documentation/SampleIMST.md) 63 | 64 | If you don't find an answer to some question in this documentation, 65 | please ask the 66 | [official discussion forum](https://groups.google.com/forum/#!forum/atomit-users)! 67 | 68 | 69 | Licensing 70 | --------- 71 | 72 | The Atom-IT server is provided as free and open-source software 73 | licensed under GPLv3+ courtesy of [WSL](http://www.wsl.be/). WSL is 74 | the key partner of techno-entrepreneurs in the Walloon region of 75 | Belgium. The Atom-IT server was created as a shared platform to 76 | support the [Atom-IT project](http://www.atomit.be/) by WSL. 77 | 78 | -------------------------------------------------------------------------------- /Framework/Filters/CounterSourceFilter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "CounterSourceFilter.h" 33 | 34 | #include 35 | 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | SourceFilter::FetchStatus CounterSourceFilter::Fetch(Message& message) 41 | { 42 | if (counter_ >= stop_) 43 | { 44 | return FetchStatus_Done; 45 | } 46 | else 47 | { 48 | boost::this_thread::sleep(delay_); 49 | message.SetMetadata(metadata_); 50 | message.SetValue(boost::lexical_cast(counter_)); 51 | counter_ += static_cast(increment_); 52 | return FetchStatus_Success; 53 | } 54 | } 55 | 56 | 57 | CounterSourceFilter::CounterSourceFilter(const std::string& name, 58 | ITimeSeriesManager& manager, 59 | const std::string& timeSeries) : 60 | SourceFilter(name, manager, timeSeries), 61 | metadata_("text/plain"), 62 | counter_(0), 63 | stop_(100), 64 | delay_(boost::posix_time::milliseconds(100)) 65 | { 66 | } 67 | 68 | 69 | void CounterSourceFilter::SetRange(int64_t start, 70 | int64_t stop) 71 | { 72 | if (start > stop) 73 | { 74 | throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 75 | } 76 | else 77 | { 78 | counter_ = start; 79 | stop_ = stop; 80 | } 81 | } 82 | 83 | 84 | void CounterSourceFilter::SetIncrement(unsigned int increment) 85 | { 86 | if (increment == 0) 87 | { 88 | throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 89 | } 90 | else 91 | { 92 | increment_ = increment; 93 | } 94 | } 95 | 96 | 97 | void CounterSourceFilter::SetDelay(unsigned int milliseconds) 98 | { 99 | delay_ = boost::posix_time::milliseconds(milliseconds); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Framework/Filters/CSVFileSinkFilter.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "CSVFileSinkFilter.h" 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | namespace AtomIT 40 | { 41 | static std::string Escape(const std::string& s) 42 | { 43 | // Replace double-quotes by two double-quotes 44 | return boost::replace_all_copy(s, "\"", "\"\""); 45 | } 46 | 47 | 48 | void CSVFileSinkFilter::GetHeader(std::string& header) 49 | { 50 | if (addHeader_) 51 | { 52 | header = "Time series,Timestamp,Metadata,Value\r\n"; 53 | } 54 | else 55 | { 56 | header.clear(); 57 | } 58 | } 59 | 60 | 61 | bool CSVFileSinkFilter::Encode(std::string& result, 62 | const std::string& inputTimeSeries, 63 | const Message& message) 64 | { 65 | result = ("\"" + Escape(inputTimeSeries) + "\"," + 66 | boost::lexical_cast(message.GetTimestamp()) + 67 | "," + Escape(message.GetMetadata()) + ",\""); 68 | 69 | if (base64_) 70 | { 71 | std::string s; 72 | Orthanc::Toolbox::EncodeBase64(s, message.GetValue()); 73 | assert(s.find('"') == std::string::npos); // Base64 should not contain double-quotes 74 | result += s; 75 | } 76 | else 77 | { 78 | result += Escape(message.GetValue()); 79 | } 80 | 81 | result += "\"\r\n"; 82 | 83 | return true; 84 | } 85 | 86 | 87 | CSVFileSinkFilter::CSVFileSinkFilter(const std::string& name, 88 | ITimeSeriesManager& manager, 89 | const std::string& timeSeries, 90 | FileWritersPool& pool, 91 | const boost::filesystem::path& path) : 92 | SharedFileSinkFilter(name, manager, timeSeries, pool, path), 93 | addHeader_(false), 94 | base64_(true) 95 | { 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Framework/LoRa/FrameEncryptionKey.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "PHYPayload.h" 35 | #include "UnsignedInteger128.h" 36 | 37 | namespace AtomIT 38 | { 39 | namespace LoRa 40 | { 41 | class FrameEncryptionKey 42 | { 43 | private: 44 | UnsignedInteger128 key_; 45 | 46 | FrameEncryptionKey() 47 | { 48 | } 49 | 50 | void PrepareMainBlock(UnsignedInteger128& block, 51 | MessageDirection direction, 52 | const uint32_t deviceAddress, 53 | uint32_t frameCounter, // WARNING: Not uint16_t! 54 | uint8_t headerByte, 55 | uint8_t trailerByte) const; 56 | 57 | void PrepareSessionKey(std::string& result, 58 | MessageDirection direction, 59 | const uint32_t deviceAddress, 60 | uint32_t frameCounter, // WARNING: Not uint16_t! 61 | size_t frameSize) const; 62 | 63 | public: 64 | explicit FrameEncryptionKey(const UnsignedInteger128& key) : key_(key) 65 | { 66 | } 67 | 68 | std::string FormatKey(bool upcase) const 69 | { 70 | return key_.Format(upcase); 71 | } 72 | 73 | static FrameEncryptionKey ParseHexadecimal(const std::string& key); 74 | 75 | void Apply(std::string& target, 76 | const std::string& source, 77 | MessageDirection direction, 78 | const uint32_t deviceAddress, 79 | uint32_t frameCounter) const; 80 | 81 | void Apply(std::string& target, 82 | const PHYPayload& payload, 83 | uint16_t highFrameCounter) const; 84 | 85 | uint32_t ComputeMIC(const PHYPayload& payload, 86 | uint16_t highFrameCounter); 87 | 88 | bool CheckMIC(const PHYPayload& payload, 89 | uint16_t highFrameCounter); 90 | }; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Framework/Filters/SourceFilter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "IFilter.h" 35 | #include "../TimeSeries/TimeSeriesWriter.h" 36 | 37 | namespace AtomIT 38 | { 39 | // Filter with 0 input and 1 output 40 | class SourceFilter : public IFilter 41 | { 42 | private: 43 | std::string name_; 44 | ITimeSeriesManager& manager_; 45 | std::string timeSeries_; 46 | TimeSeriesWriter writer_; 47 | unsigned int maxMessages_; 48 | TimestampType defaultTimestampType_; 49 | 50 | bool WaitForRoom(); 51 | 52 | protected: 53 | enum FetchStatus 54 | { 55 | FetchStatus_Success, // The message is read and available 56 | FetchStatus_Done, // The source has been cleared out 57 | FetchStatus_Invalid // The message was invalid, continue reading 58 | }; 59 | 60 | // Wait for an incoming message. The method should wait for at 61 | // least 100ms if no message arrives to avoid active 62 | // waiting. Returns "true" if a message was received. 63 | virtual FetchStatus Fetch(Message& message) = 0; 64 | 65 | public: 66 | SourceFilter(const std::string& name, 67 | ITimeSeriesManager& manager, 68 | const std::string& timeSeries); 69 | 70 | void SetDefaultTimestampType(TimestampType type); 71 | 72 | TimestampType GetDefaultTimestampType() const 73 | { 74 | return defaultTimestampType_; 75 | } 76 | 77 | void SetMaxPendingMessages(unsigned int count) 78 | { 79 | maxMessages_ = count; 80 | } 81 | 82 | unsigned int GetMaxPendingMessages() const 83 | { 84 | return maxMessages_; 85 | } 86 | 87 | virtual std::string GetName() const 88 | { 89 | return name_; 90 | } 91 | 92 | virtual void Start() 93 | { 94 | } 95 | 96 | virtual bool Step(); 97 | 98 | virtual void Stop() 99 | { 100 | } 101 | }; 102 | } 103 | -------------------------------------------------------------------------------- /Framework/TimeSeries/MemoryBackend/MemoryTimeSeriesContent.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace AtomIT 40 | { 41 | // WARNING: This class is *not* thread-safe 42 | class MemoryTimeSeriesContent : public boost::noncopyable 43 | { 44 | private: 45 | class Item; 46 | 47 | typedef std::map Content; 48 | 49 | Content content_; 50 | uint64_t size_; 51 | uint64_t maxLength_; 52 | uint64_t maxSize_; 53 | bool hasLastTimestamp_; 54 | int64_t lastTimestamp_; 55 | 56 | void RemoveOldest(); 57 | 58 | void SetValue(int64_t timestamp, 59 | const std::string& metadata, 60 | const std::string& value); 61 | 62 | public: 63 | MemoryTimeSeriesContent(uint64_t maxLength, 64 | uint64_t maxSize); 65 | 66 | virtual ~MemoryTimeSeriesContent(); 67 | 68 | void DeleteRange(int64_t start, 69 | int64_t end); 70 | 71 | bool SeekFirst(int64_t& result) const; 72 | 73 | bool SeekLast(int64_t& result) const; 74 | 75 | bool SeekNearest(int64_t& result, 76 | int64_t timestamp) const; 77 | 78 | bool SeekNext(int64_t& result, 79 | int64_t timestamp) const; 80 | 81 | bool SeekPrevious(int64_t& result, 82 | int64_t timestamp) const; 83 | 84 | bool Read(std::string& metadata, 85 | std::string& value, 86 | int64_t timestamp) const; 87 | 88 | bool Append(int64_t timestamp, 89 | const std::string& metadata, 90 | const std::string& value); 91 | 92 | void GetStatistics(uint64_t& length, 93 | uint64_t& size) const; 94 | 95 | void ClearContent(); 96 | 97 | bool GetLastTimestamp(int64_t& result) const; 98 | }; 99 | } 100 | -------------------------------------------------------------------------------- /Framework/LoRa/UnsignedInteger128.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace AtomIT 39 | { 40 | namespace LoRa 41 | { 42 | class UnsignedInteger128 : public boost::noncopyable 43 | { 44 | public: 45 | static const size_t SIZE = 16; 46 | 47 | private: 48 | uint8_t buffer_[SIZE]; 49 | 50 | public: 51 | UnsignedInteger128() 52 | { 53 | } 54 | 55 | UnsignedInteger128(const UnsignedInteger128& other); 56 | 57 | explicit UnsignedInteger128(const uint8_t buffer[SIZE]); 58 | 59 | void Assign(const UnsignedInteger128& other); 60 | 61 | void AssignZero(); 62 | 63 | void ShiftLeftOneBit(); 64 | 65 | uint8_t GetByte(unsigned int pos) const; 66 | 67 | void SetByte(unsigned int pos, 68 | uint8_t value); 69 | 70 | void Copy(unsigned int offset, 71 | const uint8_t* value, 72 | unsigned int size); 73 | 74 | void Copy(unsigned int offset, 75 | uint32_t value); 76 | 77 | static UnsignedInteger128 ParseHexadecimal(const std::string& buffer); 78 | 79 | std::string Format(bool upcase) const; 80 | 81 | const void* GetBuffer() const 82 | { 83 | return buffer_; 84 | } 85 | 86 | void ApplyXOR(const UnsignedInteger128& key); 87 | 88 | static UnsignedInteger128 EncryptAES(const UnsignedInteger128& key, 89 | const UnsignedInteger128& data); 90 | 91 | static UnsignedInteger128 DecryptAES(const UnsignedInteger128& key, 92 | const UnsignedInteger128& data); 93 | 94 | void GenerateCMACSubkey(UnsignedInteger128& k1, 95 | UnsignedInteger128& k2) const; 96 | 97 | UnsignedInteger128 ComputeCMAC(const std::string& message) const; }; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Framework/Message.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "Message.h" 33 | 34 | #include 35 | #include 36 | 37 | namespace AtomIT 38 | { 39 | Message::Message() : 40 | type_(TimestampType_Default), 41 | timestamp_(0) 42 | { 43 | } 44 | 45 | 46 | void Message::SetTimestampType(TimestampType type) 47 | { 48 | if (type == TimestampType_Fixed) 49 | { 50 | // Use "SetTimestamp()" to fix the timestamp 51 | throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType); 52 | } 53 | else 54 | { 55 | type_ = type; 56 | } 57 | } 58 | 59 | 60 | int64_t Message::GetTimestamp() const 61 | { 62 | if (type_ != TimestampType_Fixed) 63 | { 64 | throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType); 65 | } 66 | else 67 | { 68 | return timestamp_; 69 | } 70 | } 71 | 72 | 73 | void Message::SetTimestamp(int64_t timestamp) 74 | { 75 | type_ = TimestampType_Fixed; 76 | timestamp_ = timestamp; 77 | } 78 | 79 | 80 | std::string Message::FormatValue() const 81 | { 82 | if (Orthanc::Toolbox::IsAsciiString(value_.c_str(), value_.size())) 83 | { 84 | return value_; 85 | } 86 | else 87 | { 88 | return "(binary)"; 89 | } 90 | } 91 | 92 | 93 | void Message::Format(Json::Value& result) const 94 | { 95 | result = Json::objectValue; 96 | 97 | if (type_ == TimestampType_Fixed) 98 | { 99 | result["timestamp"] = static_cast(timestamp_); 100 | } 101 | 102 | result["metadata"] = metadata_; 103 | 104 | if (Orthanc::Toolbox::IsAsciiString(value_.c_str(), value_.size())) 105 | { 106 | result["value"] = value_; 107 | result["base64"] = false; 108 | } 109 | else 110 | { 111 | std::string s; 112 | Orthanc::Toolbox::EncodeBase64(s, value_); 113 | result["value"] = s; 114 | result["base64"] = true; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Framework/LoRa/LoRaEnumerations.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "LoRaEnumerations.h" 33 | 34 | #include 35 | 36 | namespace AtomIT 37 | { 38 | namespace LoRa 39 | { 40 | const char* EnumerationToString(MessageType type) 41 | { 42 | switch (type) 43 | { 44 | case MessageType_ConfirmedDataDown: 45 | return "Confirmed data down"; 46 | 47 | case MessageType_ConfirmedDataUp: 48 | return "Confirmed data up"; 49 | 50 | case MessageType_JoinAccept: 51 | return "Join accept"; 52 | 53 | case MessageType_JoinRequest: 54 | return "Join request"; 55 | 56 | case MessageType_Proprietary: 57 | return "Proprietary"; 58 | 59 | case MessageType_Reserved: 60 | return "RFU"; 61 | 62 | case MessageType_UnconfirmedDataDown: 63 | return "Unconfirmed data down"; 64 | 65 | case MessageType_UnconfirmedDataUp: 66 | return "Unconfirmed data up"; 67 | 68 | default: 69 | throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 70 | } 71 | } 72 | 73 | const char* EnumerationToString(MessageDirection direction) 74 | { 75 | switch (direction) 76 | { 77 | case MessageDirection_Uplink: 78 | return "Uplink"; 79 | 80 | case MessageDirection_Downlink: 81 | return "Downlink"; 82 | 83 | default: 84 | throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 85 | } 86 | } 87 | 88 | MessageDirection GetMessageDirection(MessageType type) 89 | { 90 | switch (type) 91 | { 92 | case MessageType_ConfirmedDataDown: 93 | case MessageType_UnconfirmedDataDown: 94 | return MessageDirection_Downlink; 95 | 96 | case MessageType_ConfirmedDataUp: 97 | case MessageType_UnconfirmedDataUp: 98 | return MessageDirection_Uplink; 99 | 100 | default: 101 | throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Framework/LoRa/MACPayload.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include "PHYPayload.h" 35 | 36 | namespace AtomIT 37 | { 38 | namespace LoRa 39 | { 40 | class MACPayload 41 | { 42 | private: 43 | std::string buffer_; 44 | uint32_t deviceAddress_; 45 | uint8_t fctrl_; 46 | uint16_t frameCounter_; 47 | size_t foptsLength_; 48 | uint8_t fport_; 49 | size_t frameOffset_; 50 | size_t frameSize_; 51 | 52 | void Parse(); 53 | 54 | MACPayload() 55 | { 56 | } 57 | 58 | public: 59 | explicit MACPayload(const PHYPayload& physical); 60 | 61 | static MACPayload ParseHexadecimal(const std::string& message); 62 | 63 | static MACPayload FromBuffer(const std::string& buffer); 64 | 65 | const std::string& GetBuffer() const 66 | { 67 | return buffer_; 68 | } 69 | 70 | uint32_t GetDeviceAddress() const 71 | { 72 | return deviceAddress_; 73 | } 74 | 75 | uint16_t GetFrameCounter() const 76 | { 77 | return frameCounter_; 78 | } 79 | 80 | uint8_t GetFCtrl() const 81 | { 82 | return fctrl_; 83 | } 84 | 85 | size_t GetFOptsLength() const 86 | { 87 | return foptsLength_; 88 | } 89 | 90 | void GetFOpts(std::string& result) const; 91 | 92 | uint8_t GetFPort() const 93 | { 94 | return fport_; 95 | } 96 | 97 | size_t GetFrameSize() const 98 | { 99 | return frameSize_; 100 | } 101 | 102 | void GetFramePayload(std::string& result) const; 103 | 104 | bool HasADR() const; 105 | 106 | bool HasACK() const; 107 | 108 | bool HasRFU(MessageDirection direction) const; 109 | 110 | bool HasRFU(MessageType type) const; 111 | 112 | bool GetFPending(MessageDirection direction) const; 113 | 114 | bool GetFPending(MessageType type) const; 115 | 116 | bool HasADRACKReq(MessageDirection direction) const; 117 | 118 | bool HasADRACKReq(MessageType type) const; 119 | 120 | void GetFHDR(std::string& result) const; 121 | }; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Framework/MQTT/MQTTClientWrapper.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #include "MQTTClientWrapper.h" 33 | 34 | #include 35 | 36 | namespace AtomIT 37 | { 38 | namespace MQTT 39 | { 40 | bool MQTTClientWrapper::Connect() 41 | { 42 | if (client_.get() == NULL) 43 | { 44 | // "Start()" must have been called beforehand 45 | throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 46 | } 47 | 48 | bool justConnected = false; 49 | 50 | if (!client_->IsConnected()) 51 | { 52 | client_->Connect(broker_, clientId_); 53 | justConnected = true; 54 | } 55 | 56 | if (client_->IsConnected()) 57 | { 58 | if (justConnected && 59 | !topics_.empty()) 60 | { 61 | client_->Subscribe(topics_); 62 | } 63 | 64 | return true; 65 | } 66 | else 67 | { 68 | return false; 69 | } 70 | } 71 | 72 | 73 | void MQTTClientWrapper::Start() 74 | { 75 | if (client_.get() != NULL) 76 | { 77 | throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 78 | } 79 | else 80 | { 81 | client_.reset(new SynchronousClient); 82 | } 83 | } 84 | 85 | 86 | MQTTClientWrapper::Accessor::Accessor(MQTTClientWrapper& that) 87 | { 88 | if (that.Connect()) 89 | { 90 | client_ = that.client_.get(); 91 | } 92 | else 93 | { 94 | client_ = NULL; 95 | } 96 | } 97 | 98 | 99 | SynchronousClient& MQTTClientWrapper::Accessor::GetClient() const 100 | { 101 | if (client_ == NULL) 102 | { 103 | throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 104 | } 105 | else 106 | { 107 | return *client_; 108 | } 109 | } 110 | 111 | 112 | void MQTTClientWrapper::Stop() 113 | { 114 | if (client_.get() == NULL) 115 | { 116 | throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 117 | } 118 | else 119 | { 120 | client_.reset(NULL); 121 | } 122 | } 123 | } 124 | } 125 | 126 | -------------------------------------------------------------------------------- /Framework/ConfigurationSection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Atom-IT - A Lightweight, RESTful microservice for IoT 3 | * Copyright (C) 2017 Sebastien Jodogne, WSL S.A., Belgium 4 | * 5 | * This program is free software: you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation, either version 3 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * In addition, as a special exception, the copyright holders of this 11 | * program give permission to link the code of its release with the 12 | * OpenSSL project's "OpenSSL" library (or with modified versions of it 13 | * that use the same license as the "OpenSSL" library), and distribute 14 | * the linked executables. You must obey the GNU General Public License 15 | * in all respects for all of the code used other than "OpenSSL". If you 16 | * modify file(s) with this exception, you may extend this exception to 17 | * your version of the file(s), but you are not obligated to do so. If 18 | * you do not wish to do so, delete this exception statement from your 19 | * version. If you delete this exception statement from all source files 20 | * in the program, then also delete it here. 21 | * 22 | * This program is distributed in the hope that it will be useful, but 23 | * WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | * General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | **/ 30 | 31 | 32 | #pragma once 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace AtomIT 40 | { 41 | class ConfigurationSection : public boost::noncopyable 42 | { 43 | private: 44 | Json::Value configuration_; 45 | 46 | public: 47 | ConfigurationSection() : 48 | configuration_(Json::objectValue) 49 | { 50 | } 51 | 52 | explicit ConfigurationSection(const Json::Value& value); 53 | 54 | ConfigurationSection(const ConfigurationSection& parent, 55 | const std::string& section); 56 | 57 | ConfigurationSection(const ConfigurationSection& parent, 58 | const std::string& section, 59 | size_t index); 60 | 61 | void LoadFile(const boost::filesystem::path& path); 62 | 63 | size_t GetSize(const std::string& section) const; 64 | 65 | std::string Format() const 66 | { 67 | return configuration_.toStyledString(); 68 | } 69 | 70 | void ListMembers(std::set& target) const; 71 | 72 | bool HasItem(const std::string& name) const 73 | { 74 | return configuration_.isMember(name); 75 | } 76 | 77 | bool GetStringParameter(std::string& value, 78 | const std::string& name) const; 79 | 80 | bool GetIntegerParameter(int& value, 81 | const std::string& name) const; 82 | 83 | bool GetUnsignedIntegerParameter(unsigned int& value, 84 | const std::string& name) const; 85 | 86 | bool GetBooleanParameter(bool& value, 87 | const std::string& name) const; 88 | 89 | std::string GetMandatoryStringParameter(const std::string& name) const; 90 | 91 | int GetMandatoryIntegerParameter(const std::string& name) const; 92 | 93 | unsigned int GetMandatoryUnsignedIntegerParameter(const std::string& name) const; 94 | 95 | bool GetMandatoryBooleanParameter(const std::string& name) const; 96 | 97 | std::string GetStringArrayItem(const std::string& name, 98 | size_t index) const; 99 | }; 100 | } 101 | -------------------------------------------------------------------------------- /Documentation/Compilation.md: -------------------------------------------------------------------------------- 1 | Compilation 2 | =========== 3 | 4 | The Atom-IT server is mainly written in C++. Its infrastructure is 5 | based upon the [Orthanc framework](https://www.orthanc-server.com/) 6 | for medical imaging. As a consequence, please refer to the 7 | [build instructions for Orthanc](https://bitbucket.org/sjodogne/orthanc/src/default/LinuxCompilation.txt?fileviewer=file-view-default) 8 | to get an insight about how to compile it for your platform. 9 | 10 | 11 | Ubuntu 16.04 LTS 12 | ---------------- 13 | 14 | The following build instruction is known to work properly on Ubuntu 15 | 16.04: 16 | 17 | ```bash 18 | $ mkdir Build && cd Build 19 | $ cmake .. -DCMAKE_BUILD_TYPE=Release \ 20 | -DALLOW_DOWNLOADS=ON \ 21 | -DUSE_SYSTEM_MONGOOSE=OFF \ 22 | -DUSE_SYSTEM_PAHO=OFF \ 23 | -DUSE_SYSTEM_GOOGLE_TEST=OFF 24 | $ make 25 | ``` 26 | 27 | 28 | Static Linking 29 | -------------- 30 | 31 | Static linking against all third-party dependencies is also available 32 | in order to provide maximum portability, notably for Microsoft Windows 33 | and Apple OS X: 34 | 35 | ```bash 36 | $ mkdir Build && cd Build 37 | $ cmake .. -DCMAKE_BUILD_TYPE=Release -DSTATIC_BUILD=ON 38 | $ make 39 | ``` 40 | 41 | 42 | Docker 43 | ------ 44 | 45 | [Docker](https://en.wikipedia.org/wiki/Docker_(software)) images for the Atom-IT server are freely available on the [DockerHub](https://hub.docker.com/r/jodogne/atomit/) platform. The source code of the corresponding Docker images is available within [this repository](../Resources/Docker/), and are built on the top of the lightweight [Alphine distribution](https://hub.docker.com/_/alpine/). 46 | 47 | ### Starting Atom-IT 48 | 49 | Here is the command to start the Atom-IT server using Docker: 50 | 51 | ```bash 52 | $ sudo docker pull jodogne/atomit 53 | $ sudo docker run -p 8042:8042 --rm jodogne/atomit 54 | ``` 55 | 56 | The Web interface and [REST API](RestApi.md) are then accessible on http://localhost:8042/. The default username is `atomit` and the default password is `atomit`. This Docker image is configured to [auto-create time series using the memory backend](Configuration.md#auto-creation-of-time-series). 57 | 58 | Passing additional command-line options (e.g. to make Atom-IT verbose) can be done as follows (note the `/etc/atomit/atomit.json` option that is required for the server to find its configuration file): 59 | 60 | ```bash 61 | $ sudo docker run -p 8042:8042 --rm jodogne/atomit /etc/atomit/atomit.json --verbose 62 | ``` 63 | 64 | ### Fine-tuning the configuration 65 | 66 | You can generate a custom configuration file for the Atom-IT server as follows. First, retrieve the default [configuration file](Configuration.md): 67 | 68 | ```bash 69 | $ sudo docker run --rm --entrypoint=cat jodogne/atomit /etc/atomit/atomit.json > /tmp/atomit.json 70 | ``` 71 | 72 | Then, edit the just-generated file `/tmp/atomit.json` and restart Atom-IT with your updated configuration: 73 | 74 | ```bash 75 | $ sudo docker run -p 8042:8042 --rm -v /tmp/atomit.json:/etc/atomit/atomit.json:ro jodogne/atomit 76 | ``` 77 | 78 | ### Making storage persistent 79 | 80 | The filesystem of Docker containers is volatile (its content is deleted once the container stops). You can make the Atom-IT database persistent by defining a SQLite database in the `/var/lib/atomit/db` folder of the container, and mapping this folder somewhere in the filesystem of your Linux host, e.g.: 81 | 82 | ```bash 83 | $ cat << EOF > /tmp/atomit.json 84 | { 85 | "AutoTimeSeries" : { 86 | "Backend" : "SQLite", 87 | "Path" : "/var/lib/atomit/db/atomit.db" 88 | }, 89 | "HttpPort" : 8042, 90 | "RemoteAccessAllowed" : true, 91 | "AuthenticationEnabled" : true, 92 | "RegisteredUsers" : { 93 | "atomit" : "atomit" 94 | } 95 | } 96 | EOF 97 | $ sudo docker run -p 8042:8042 --rm \ 98 | -v /tmp/atomit.json:/etc/atomit/atomit.json:ro \ 99 | -v /tmp/atomit-db/:/var/lib/atomit/db/ \ 100 | jodogne/atomit /etc/atomit/atomit.json --verbose 101 | ``` 102 | --------------------------------------------------------------------------------