Giter Site home page Giter Site logo

josemotta / iot.starter.api Goto Github PK

View Code? Open in Web Editor NEW
23.0 2.0 9.0 32.25 MB

Tests with ASP.NET Core Web API for Raspberry Pi

Batchfile 0.62% Shell 1.33% C# 91.39% HTML 0.03% CSS 2.73% JavaScript 3.89%
aspnetcorewebapi docker-compose docker-image swagger aspnetcore api raspberry-pi

iot.starter.api's Introduction

API First Design

The API First Design strategy is used to develop ASP.NET Core Web APIs automatically generated by Swagger Hub. The faster build and availability of Visual Studio environment are the key advantages of this starter kit targeting the Raspberry Pi.

ASP.NET Core Web API for Raspberry Pi

Starting from a Swagger API definition, an ASP.NET Core Web API is automatically generated by Swagger Hub. The code is pushed to github and then loaded by a Windows x64 machine and upgraded to ASP.NET Core 2.0, using Visual Studio 2017.

A multi-stage docker image build is accomplished at the speedy Windows x64 machine, generating code of linux-arm framework. The image container is pushed to the cloud and then pulled back into a Raspberry Pi with Raspbian 9.1 stretch installed.

Model:

  • Restlet generates API and exports swagger.json
  • Swagger Hub imports file and generates server stub

x64 machine:

  • Install Docker
  • Pull server stub from github
  • Upgrade to .NET Core 2 and Docker support
  • Create multi-stage image build for server stub
  • Compiles at x64 machine for linux-arm framework
  • Push Docker image to cloud

Raspberry Pi (hostname "rpi")

  • Raspbian GNU/Linux 9.1 (stretch)
  • Install Docker
  • Run Docker image

Tests

Project 1: aspnetcore

Testing API at port:5000 with code generated from SwaggerHub.

Links:
https://app.swaggerhub.com/apis/josemottalopes/contacts-api/1.2.0
https://github.com/josemotta/Api
https://hub.docker.com/r/josemottalopes/io.swagger/

x64: Build

cd /aspnetcore
docker-compose -f docker-compose.ci.build.yml build   
docker push josemottalopes/io.swagger:latest  

arm: RaspberryPi (hostname "rpi")

docker run --privileged -p 5000:5000 -d josemottalopes/io.swagger

any browser: Client Test

http://rpi:5000/swagger/ui/index.html

Project 2: home-web

Starter for Home project at port:5010

Links:
https://app.swaggerhub.com/apis/josemottalopes/home-api/1.0.1
https://github.com/josemotta/Api
https://hub.docker.com/r/josemottalopes/home-web/

x64: Build

cd /home-web
docker-compose -f docker-compose.ci.build.yml build   
docker push josemottalopes/home-web:latest  

arm: RaspberryPi (hostname "rpi")

docker run --privileged -p 5010:5010 -d josemottalopes/home-web

any browser: Client Test

http://rpi:5010/swagger/ui/index.html

Project 3: RazorPageShop

Web UI Starter for Home project (port:80) using RazorPageShop from Marcelo Oliveira as a template. Another option would be a "regular" ASP.NET Core MVC Application.

Razor
From MVC to Razor Pages

ASP.NET Core Application
Building an ASP.NET Core Application with Web API and Code First Development

React
React Shop - A Tiny E-Commerce

DAL/DB (check .net 2.0 support?)
Building Entity Framework Disconnected Generic Repository

Links:
https://github.com/josemotta/Api
https://hub.docker.com/r/josemottalopes/home-pi-1/

x64: Build

cd razorpageshop
docker-compose -f docker-compose.pi.yml build   
docker push josemottalopes/home-pi-1:latest  

arm: RaspberryPi (hostname "rpi")

docker run --privileged -p 80:80 -d josemottalopes/home-pi-1

any browser: Client Test

http://rpi

Projects running at RPI

The commands start clearing all docker containers and images:

# Stop the containers
root@lumi:# docker stop $(docker ps -a -q)

# Delete all containers
root@lumi:# docker rm $(docker ps -a -q)

# Delete all images
root@lumi:# docker rmi --force $(docker images -q)

Then all projects are started, downloading images from cloud (DockerHub) to RPI:

#alias homeweb='docker run --privileged -p 5010:5010 -d josemottalopes/home-web:latest'
#alias ioswagger='docker run --privileged -p 5000:5000 -d josemottalopes/io.swagger:latest'

root@lumi:# homeweb
Unable to find image 'josemottalopes/home-web:latest' locally
latest: Pulling from josemottalopes/home-web
e7ea15fa8fb2: Pull complete
14ae8f7a598f: Pull complete
15d4c9904a5d: Pull complete
4e1120917082: Pull complete
b8d414906f99: Pull complete
0dfe3a2727e0: Pull complete
Digest: sha256:48da4f5cff21fd7d1f44c0e129a9b0de3114e48124d491f1da1f1a1ecfa1cf33
Status: Downloaded newer image for josemottalopes/home-web:latest
2e8be31f9e5e641ddfb94e3db5d4770c039dedc410c0d66f86555e9286e34f0a

root@lumi:/# ioswagger
Unable to find image 'josemottalopes/io.swagger:latest' locally
latest: Pulling from josemottalopes/io.swagger
e7ea15fa8fb2: Already exists
14ae8f7a598f: Already exists
15d4c9904a5d: Already exists
4e1120917082: Already exists
b8d414906f99: Already exists
97db2d097015: Pull complete
Digest: sha256:5eac7701f0d884d3ef6b1eeafb773014a042389ddacc7342cc8a87eaab618cf4
Status: Downloaded newer image for josemottalopes/io.swagger:latest
19285505a953d130401a42aa67017f6f7289d9838adb1b0e994cb7d841acb53a

You can notice the second project share five images with first project and they don't need to be downloaded again. The docker images and running containers are shown below:

root@lumi:~# docker ps
CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS              PORTS                    NAMES
a347c582e14e        josemottalopes/io.swagger:latest   "/bin/sh -c /app/I..."   2 minutes ago       Up 2 minutes        0.0.0.0:5000->5000/tcp   dreamy_bose
268429269f52        josemottalopes/home-web:latest     "/bin/sh -c /app/I..."   2 minutes ago       Up 2 minutes        0.0.0.0:5010->5010/tcp   epic_swirles
22337a4f50b8        josemottalopes/home-pi-1:latest    "dotnet RazorPageS..."   25 hours ago        Up 25 hours         0.0.0.0:80->80/tcp       goofy_wescoff
root@lumi:~# docker images -a
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
josemottalopes/home-pi-1    latest              7e335e37b9d3        28 hours ago        249MB
josemottalopes/home-web     latest              75e89c7c1cf5        4 weeks ago         235MB
josemottalopes/io.swagger   latest              fb9745c521f5        7 weeks ago         235MB
root@lumi:~#

There are a couple ASP.NET Core Web APIs listening to ports 5000 and 5010, each one related to a different swagger file. The Web UI is running on port 80, although the activation is not shown above.

All running

Following is a full activation after a boot, considering that all containers are already loaded.

alias yhomeweb='docker run --privileged -p 5010:5010 -d josemottalopes/home-web:latest'
alias yioswagger='docker run --privileged -p 5000:5000 -d josemottalopes/io.swagger:latest'
alias yrazor='docker run --privileged -p 80:80 -d josemottalopes/home-pi-1:latest'

root@lumi:~# yioswagger
98815f8f3381212979098b27c80fdf6f226bf10dfd237c448f8b2fc3c63bd754
root@lumi:~# yhomeweb
694c4be94e3de0789ee4822bca51c0266f1933edb8201e1953faa32dd9794656
root@lumi:~# yrazor
cf531a536076373cde0bdf1fe292997e89c5f2c2f51bc718e317930a2499cc56
root@lumi:~# docker ps
CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS              PORTS                    NAMES
cf531a536076        josemottalopes/home-pi-1:latest    "dotnet RazorPageS..."   17 seconds ago      Up 7 seconds        0.0.0.0:80->80/tcp       admiring_edison
694c4be94e3d        josemottalopes/home-web:latest     "/bin/sh -c /app/I..."   27 seconds ago      Up 16 seconds       0.0.0.0:5010->5010/tcp   youthful_colden
98815f8f3381        josemottalopes/io.swagger:latest   "/bin/sh -c /app/I..."   35 seconds ago      Up 27 seconds       0.0.0.0:5000->5000/tcp   suspicious_albattani

iot.starter.api's People

Contributors

bamplifier avatar josemotta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

iot.starter.api's Issues

how to read gpio-ir?

Hi,

Excellent guide.

A quick question. I have a Keyes_838B (as well as a simple V1838B) and would like to try option 1 (gpio-ir) without LIRC on my Raspberry Pi Zero W. How would I go about getting the data? I have everything set up according to the defaults and tried to run a python script to get the data but I ran into a "RuntimeError: Failed to add edge detection" error similar to this post. The solution there was to move to another pin where there are no secondary function conflicts, however if I move to another pin and it works (don't know, haven't tried it out yet) then what use is gpio-ir in the first place?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.