<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Phoax on Medium]]></title>
        <description><![CDATA[Stories by Phoax on Medium]]></description>
        <link>https://medium.com/@phoax?source=rss-22cf49bfeb3d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fLCZL7Pplyzy-ASJQW6YOQ.png</url>
            <title>Stories by Phoax on Medium</title>
            <link>https://medium.com/@phoax?source=rss-22cf49bfeb3d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 06:43:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@phoax/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[System environment variables in Next.js with Docker]]></title>
            <link>https://phoax.medium.com/system-environment-variables-in-next-js-with-docker-1f0754e04cde?source=rss-22cf49bfeb3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f0754e04cde</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[environment-variables]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Phoax]]></dc:creator>
            <pubDate>Mon, 29 Nov 2021 15:31:32 GMT</pubDate>
            <atom:updated>2021-11-29T15:31:32.611Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a2_r23r5TqTRpnby1Z61JQ.png" /></figure><p>Next.js is an excellent open-source development framework, one of its features is to use environment files for configuration. Unfortunately it seems difficult to create an app, Dockerize it and then use custom system environment variables when the image is run. Indeed at the build phase, config values are written in the .next/ folder, and it is difficult to change them without rebuilding the application.</p><p>This article presents a way to replace build environments variables with custom system environment variables.</p><p>This solution is inspired by this <a href="https://github.com/vercel/next.js/discussions/17641#discussioncomment-339555">GitHub example</a>.</p><h3>Next.js application</h3><h4>Create application</h4><p>Create a Next.js application:</p><pre>npx create-next-app@latest</pre><p>Set <strong>next-with-system-env </strong>for the project name:</p><pre>Need to install the following packages:                                                                                                                                                                                                                                                                                                                              <br>  create-next-app@latest<br>Ok to proceed? (y) <br>✔ What is your project named? … next-with-system-env</pre><p>Go to the application folder:</p><pre>cd next-with-system-env</pre><h4>Runtime configuration</h4><p>To allow config to be accessible to both client and server-side, edit next.config.js, in module.exports add:</p><pre>publicRuntimeConfig: {<br>  name: process.env.NAME,<br>  description: process.env.DESCRIPTION,<br>}</pre><p>To load environment variables, create an .env file with:</p><pre>NAME=Next with system env<br>DESCRIPTION=Next with system env description</pre><p>To display config values, edit /page/index.js and add:</p><pre>import getConfig from &#39;next/config&#39;<br>const { publicRuntimeConfig: config } = getConfig()<br>console.log(&#39;config:&#39;, JSON.stringify(config))</pre><p>Run the application:</p><pre>npm run dev</pre><p>The browser console should display:</p><pre>config: {&quot;app&quot;:{&quot;name&quot;:&quot;Next with system env&quot;,&quot;description&quot;:&quot;Next with system env description&quot;}}</pre><p>At this point, if you Dockerize the application with the recommended <a href="https://nextjs.org/docs/deployment#docker-image">Dockerfile</a> example, the config will be built in the image without any way to change values with system environment variables.</p><h3>Replace build config with system environment</h3><h4>Generic config for production</h4><p>Create another config file for production .env.production and add:</p><pre>NAME=APP_NEXT_NAME<br>DESCRIPTION=APP_NEXT_DESCRIPTION<br></pre><p>The APP_NEXT_… will be matched and replaced in the next steps</p><h4>Shell script to match and replace config</h4><p>Create a entrypoint.sh file and add:</p><pre>#!/bin/bash</pre><pre># no verbose<br>set +x</pre><pre># config<br>envFilename=&#39;.env.production&#39;<br>nextFolder=&#39;./.next/&#39;</pre><pre>function apply_path {<br>  # read all config file  <br>  while read line; do<br>    # no comment or not empty<br>    if [ &quot;${line:0:1}&quot; == &quot;#&quot; ] || [ &quot;${line}&quot; == &quot;&quot; ]; then<br>      continue<br>    fi<br>    <br>    # split<br>    configName=&quot;$(cut -d&#39;=&#39; -f1 &lt;&lt;&lt;&quot;$line&quot;)&quot;<br>    configValue=&quot;$(cut -d&#39;=&#39; -f2 &lt;&lt;&lt;&quot;$line&quot;)&quot;</pre><pre>    # get system env<br>    envValue=$(env | grep &quot;^$configName=&quot; | grep -oe &#39;[^=]*$&#39;);<br>    <br>    # if config found<br>    if [ -n &quot;$configValue&quot; ] &amp;&amp; [ -n &quot;$envValue&quot; ]; then<br>      # replace all<br>      echo &quot;Replace: ${configValue} with: ${envValue}&quot;<br>      find $nextFolder \( -type d -name .git -prune \) -o -type f -print0 | xargs -0 sed -i &quot;s#$configValue#$envValue#g&quot;<br>    fi<br>  done &lt; $envFilename</pre><pre>}</pre><pre>apply_path<br>echo &quot;Starting Nextjs&quot;<br>exec &quot;$@&quot;</pre><p>This script find all the APP_NEXT_… occurent in .next/ folder and replace them with system environment variables.</p><h3>Dockerize</h3><p>Create a Dockerfile and add:</p><pre># Install dependencies only when needed<br>FROM node:alpine AS deps<br># Check <a href="https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine">https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine</a> to understand why libc6-compat might be needed.<br>RUN apk add --no-cache libc6-compat<br>WORKDIR /app<br>COPY package.json ./<br>RUN yarn install --frozen-lockfile</pre><pre># Rebuild the source code only when needed<br>FROM node:alpine AS builder<br>WORKDIR /app<br>COPY . .<br>COPY --from=deps /app/node_modules ./node_modules</pre><pre>RUN yarn build &amp;&amp; yarn install --production --ignore-scripts --prefer-offline</pre><pre># Production image, copy all the files and run next<br>FROM node:alpine AS runner<br>WORKDIR /app</pre><pre>ENV NODE_ENV production</pre><pre>RUN addgroup -g 1001 -S nodejs<br>RUN adduser -S nextjs -u 1001</pre><pre># You only need to copy next.config.js if you are NOT using the default configuration<br>#COPY --from=builder /app/next.config.js ./<br>COPY --from=builder /app/public ./public<br>COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next<br>COPY --from=builder /app/node_modules ./node_modules<br>COPY --from=builder /app/package.json ./package.json<br>COPY entrypoint.sh .<br>COPY .env.production .</pre><pre># Execute script<br>RUN apk add --no-cache --upgrade bash<br>RUN [&quot;chmod&quot;, &quot;+x&quot;, &quot;./entrypoint.sh&quot;]<br>ENTRYPOINT [&quot;./entrypoint.sh&quot;]</pre><pre>USER nextjs</pre><pre>EXPOSE 3000</pre><pre>ENV PORT 3000</pre><pre># Next.js collects completely anonymous telemetry data about general usage.<br># Learn more here: <a href="https://nextjs.org/telemetry">https://nextjs.org/telemetry</a><br># Uncomment the following line in case you want to disable telemetry.<br># ENV NEXT_TELEMETRY_DISABLED 1</pre><pre>CMD [&quot;node_modules/.bin/next&quot;, &quot;start&quot;]</pre><p>The .env.production will be copied to allow the script to identify all the configuration values to replace thanks to theAPP_NEXT_… prefix.</p><p>And as explained previously, the entrypoint.sh will replace this built config values in the .next/ folder with values from the system. It needs bash to be executed.</p><h4>Test</h4><p>To test is, first build an image:</p><pre>docker build -t next-with-system-env .</pre><p>Then start the image with --env-file .env option to load system environment values:</p><pre>docker run --env-file .env next-with-system-env</pre><p>Finally go to <a href="http://localhost:3000/">http://localhost:3000</a></p><p>The browser console should display values from .env.</p><h4>Example</h4><p>A full example can be found here: <a href="https://github.com/factorim/next-with-system-env">https://github.com/factorim/next-with-system-env</a></p><h3>Conclusion</h3><p>Maybe there is a more straightforward solution the add system environment configuration in a Dockerized Nest.js application, I would be glad to know it. In the meantime, here is a way to do it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f0754e04cde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to run local SQLite commands in a Docker Container]]></title>
            <link>https://phoax.medium.com/how-to-run-local-sqlite-commands-in-a-docker-container-bcba18af69f2?source=rss-22cf49bfeb3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcba18af69f2</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[sqlite]]></category>
            <category><![CDATA[sqlite3]]></category>
            <dc:creator><![CDATA[Phoax]]></dc:creator>
            <pubDate>Thu, 14 Oct 2021 20:53:27 GMT</pubDate>
            <atom:updated>2021-10-15T09:39:01.101Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*osrTwB1PkQFGR72hfpSMoA.png" /></figure><p><a href="https://www.sqlite.org/index.html">SQLite</a> is a very simple and powerful database engine. This is a free library that implements a stand-alone, serverless, zero-configuration, transactional SQL database engine. The entire database (declarations, tables, indexes, and data) is stored in a file independent of the platform.</p><p>The database is represented by a file which often has the extension .db. For example: database.db. This file can be loaded into a project with an SQLite package or can be directly accessed with a library to run SQL queries or SQLite commands.</p><p>To directly access this file, one of the best-known libraries is the <a href="https://docs.python.org/3/library/sqlite3.html">sqlite3</a> C library. It is easy to use, but it is mandatory to install it or have the binaries to run it. But thanks to Docker containers it is possible to run local SQLite commands without installing it.</p><h3>Dump and Restore SQLite database with Docker</h3><p>Let’s have a project structure with two files in a data folder:</p><pre>.<br>..<br>data/database.db<br>data/dump.sql</pre><p>where</p><ul><li>database.db contains the SQLite database.</li><li>dump.sql contains the dump of the database.</li></ul><h4>Dump</h4><p>To generate a dump with Docker, execute:</p><pre>docker run --rm \<br>  --user $(id -u):$(id -g) \<br>  -v /$(pwd)/data:/db \<br>  keinos/sqlite3 \<br>  sh -c &quot;sqlite3 /db/database.db .dump &gt; /db/dump.sql&quot;</pre><p>--rm to automatically clean up the container.</p><p>--user $(id -u):$(id -g) is an option to get the UID and GID of the host to generate files with the same user as the host. Without it, there could be an error in the permissions to generate the file on the host.</p><p>-v /$(pwd)/data:/db is an option to mount the host/data folder in the container/db folder. It allows to write files on the container and access them directly on the host.</p><p>keinos/sqlite3 is a container image for sqlite3.</p><p>sh -c &quot;sqlite3 /db/database.db .dump &gt; /db/dump.sql&quot; is the command to dump the database. The container will write dump.sql from the database.db and with the volume, these files are directly accessed on the host. dump.sql are human-readable files and can be verified by opening them.</p><p>Dumping the schema can be done with:</p><pre>docker run --rm \<br>  --user $(id -u):$(id -g) \<br>  -v /$(pwd)/data:/db \<br>  keinos/sqlite3 \<br>  sh -c &quot;sqlite3 /db/database.db .schema &gt; /db/schema.sql&quot;</pre><h4>Restore</h4><p>To restore a database from a dump with Docker, execute:</p><pre>docker run --user $(id -u):$(id -g) \<br>  -v /$(pwd)/data:/db \<br>  keinos/sqlite3 \<br>  sh -c &quot;sqlite3 /db/database.db &lt; /db/dump.sql&quot;</pre><p>sh -c &quot;sqlite3 /db/database.db &lt; /db/dump.sql&quot; is the command to restore the database. The container will write database.db from the dump.sql and with the volume, these files can be directly accessed on the host.</p><p>For the explanation of the other options, see the Dump chapter above.</p><h3>Conclusion</h3><p>SQLite provides a light portable database that can be associated directly with services source files, and sometimes it might be useful to dump or restore a database on a system that did not have any SQLite libraries.</p><p>Docker solves it by providing a simple way to execute SQLite commands. It can be useful to simplify deployment by preventing the installation of additional libraries.</p><p>Thanks to Nelson and Samir for helping me find this solution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcba18af69f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Golang app in a container with hot reload and dynamic local package]]></title>
            <link>https://phoax.medium.com/golang-app-in-a-container-with-hot-reload-and-dynamic-local-package-e860bdc920d5?source=rss-22cf49bfeb3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e860bdc920d5</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[hot-reloading]]></category>
            <dc:creator><![CDATA[Phoax]]></dc:creator>
            <pubDate>Mon, 22 Feb 2021 22:41:21 GMT</pubDate>
            <atom:updated>2021-03-06T22:03:01.986Z</atom:updated>
            <content:encoded><![CDATA[<h3>Golang app in a container with hot reloading and dynamic local package</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hh9rqraBOrH06d_xyqWHYg.png" /></figure><p>A good way to develop Go applications is to use a Docker container to run them. In addition, having hot reloading is a useful feature to save time and directly see code updates. Finally, being able to switch easily between local packages and released packages is very important for micro-services development.</p><p>In this article, we will see a way to create an app that allows these three features.</p><h3>Requirements</h3><p>The requirement to make it work:</p><ul><li>Docker installed.</li></ul><h3>How it works</h3><h4>Container and hot reloading</h4><p>Create a container with hot reloading for a Go application is easy. In a <em>Dockerfile</em>, get this package:</p><pre>RUN go get github.com/githubnemo/CompileDaemon</pre><p>Then build and start the application with this package:</p><pre>ENTRYPOINT CompileDaemon --build=&quot;go build main.go&quot; --command=&quot;./main&quot;</pre><h4>Dynamic local package</h4><p>Using a dynamic local package is less straightforward.</p><p>Withgo get ...command, the package will be downloaded from an external source. In order to use a local package, the go mod edit -replace ...<em> </em>should be used. For example:</p><pre>$ go mod edit -replace &lt;path-to-your-repository&gt;/mypackage=~/mypackage</pre><p>But firstly, it adds local links in the go.mod file that should be removed before pushing the code (where your local doesn’t exist anymore). Secondly, local packages are not directly reachable by containers.</p><p>The idea here is to import local packages as volumes and to have two go.mod files to switch between <em>released packages</em> references and<em> local packages</em> references. Then use different commands to run each mode.</p><p>More details below.</p><h3>Create the application</h3><p>The first steps are to create a package and an application that will call the package.</p><p>In a new folder, to start we have this structure:</p><pre>myapp/<br>  Dockerfile<br>  Makefile<br>  docker-compose.yml<br>  main.go<br>mypackage/<br>  mytest/<br>    mytest.go</pre><h4>Create a simple package</h4><p>In a mytest.go, create a function that returns a simple message:</p><pre>package mytest</pre><pre>// GetMyTest just return a string<br>func GetMyTest() string {<br> message := &quot;Hello World from Mypackage&quot;<br> return message<br>}</pre><p>Then, in mypackage folder, execute the following command to create the Go module dependencies:</p><pre>$ go mod init &lt;path-to-your-repository&gt;/mypackage</pre><p>It should create mypackage/go.mod file.</p><h4>Create a simple application</h4><p>In a main.go, import, and call the package in a function that returns a simple message:</p><pre>package main</pre><pre>import (<br>  &quot;fmt&quot;<br>  &quot;&lt;path-to-your-repository&gt;/mypackage/mytest&quot;<br>)</pre><pre>func main() {<br>  message := &quot;Call Package:&quot;<br>  fmt.Println(message, mytest.GetMyTest())<br>}</pre><p>Then, in myappfolder, execute the following command to create the Go module dependencies:</p><pre>$ go mod init &lt;path-to-your-repository&gt;/myapp</pre><p>It should create myapp/go.mod file.</p><h3>Dockerize the application</h3><p>Set the context folder in thedocker-compose.yml:</p><pre>version: &quot;3&quot;<br>services:<br>  myapp:<br>    build:<br>      dockerfile: Dockerfile<br>      context: ./</pre><p>Then in the Dockerfile choose the/go/src/app as WORKDIR and copy the app, download the packages, build and start with hot reloading package</p><pre>FROM golang:latest</pre><pre>WORKDIR /go/src/app</pre><pre>COPY . .</pre><pre>RUN go mod download -x</pre><pre>RUN go get github.com/githubnemo/CompileDaemon</pre><pre>ENTRYPOINT CompileDaemon --build=&quot;go build main.go&quot; --command=&quot;./main&quot;</pre><p>Create a copy of your go.mod, and add the local package:</p><pre>$ cp go.mod go.local.mod<br>$ go mod edit -replace &lt;path-to-your-repository&gt;/mypackage=~/mypackage go.local.mod</pre><p>Indocker-compose.yml add myappandmypackage as volume, and override thego.mod by ago.local.mod that will contain references to local packages; ${GO_MOD} is a variable that will contain go.mod or go.local.mod:</p><pre>version: &quot;3&quot;<br>services:<br>  myapp:<br>    build:<br>      dockerfile: Dockerfile<br>      context: ./<br>    volumes:<br>      - ./:/go/src/app/<br>      - ./${GO_MOD}:/go/src/app/go.mod<br>      - ../mypackage:/go/src/mypackage</pre><p>Finally, create a Makefile to be able to switch between usages. The GO_MOD environment variable is injected before running the docker-compose up command:</p><pre>SERVICE := go-hotreload</pre><pre>dev:<br> GO_MOD=go.mod docker-compose up</pre><pre>dev-build:<br> GO_MOD=go.mod docker-compose up --build</pre><pre>dev-local:<br> GO_MOD=go.local.mod docker-compose up</pre><pre>dev-local-build:<br> GO_MOD=go.local.mod docker-compose up --build</pre><h3>How to use</h3><p>To edit your app and your local package, execute:</p><pre>$ make dev-local</pre><p>To edit your app and use the released package, execute:</p><pre>$ make dev</pre><h3>Conclusion</h3><p>A constraint in this solution is to manually add each package as a volume in the docker-compose.yml. But for simple usage, it does the job.</p><p>Source code can be found here: <a href="https://github.com/phoax/go-hotreload">https://github.com/phoax/go-hotreload</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e860bdc920d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to live stream on Zoom with OBS?]]></title>
            <link>https://phoax.medium.com/how-to-live-stream-on-zoom-with-obs-72b23aa9721a?source=rss-22cf49bfeb3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/72b23aa9721a</guid>
            <category><![CDATA[live-streaming]]></category>
            <category><![CDATA[zoom]]></category>
            <category><![CDATA[obs]]></category>
            <dc:creator><![CDATA[Phoax]]></dc:creator>
            <pubDate>Sun, 31 May 2020 10:32:37 GMT</pubDate>
            <atom:updated>2020-06-10T07:59:38.593Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*WoToau8A4HBMkC7RQmXjwg.png" /></figure><h3>How to live stream on Zoom with OBS on Windows?</h3><p>Zoom is one of the most used software to make video conferencing, and OBS (Open Broadcaster Software) is a famous free software for video composition used for web streaming.</p><p>In this article, we will see how to use OBS video compositions to live stream on Zoom. The goal is to create a virtual webcam with the output of OBS, and open this virtual webcam on Zoom.</p><p>There are two ways to the emulate a webcam with OBS’s output. The first is with the OBS VitualCam plugin, and the second is with NDI tools instead. VirtualCam is easier to use but the quality seems a little worse than NDI.</p><h3>Requirements</h3><p>Before starting you need to have:</p><ul><li>Windows 10, but it should work with other OS.</li><li>Zoom: <a href="https://zoom.us/">https://zoom.us/</a></li><li>OBS: <a href="https://obsproject.com/">https://obsproject.com/</a></li></ul><p>And knowledge on how to create scenes on OBS; there are plenty of tutorials among the Net.</p><h3>Virtual webcam with VirtualCam plugin</h3><p>First way to emulate a webcam is to use <strong>VirtualCam</strong> plugin.</p><h4>Install VirtualCam</h4><p>Go to <a href="https://obsproject.com/forum/resources/obs-virtualcam.949/">https://obsproject.com/forum/resources/obs-virtualcam.949/</a> and click on <strong>Go to download</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hk_uE3BHmkdQoAwuss5r5g.png" /></figure><p>Once downloaded, execute <strong>obs-virtualcam-2.0.5-Windows-installer.exe</strong> file.</p><h4>Configure OBS</h4><p>Start OBS software.</p><p>In the Tools menu, <strong>VirtualCam</strong> should be available. Click on <strong>VirtualCam</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*pJuh4MmfAWVcr9WQG3D8jA.png" /></figure><p>In the <strong>VirtualCam </strong>dialog, the name of the virtual webcam is displayed on <strong>Target Camera: OBS-Camera.</strong></p><p>Click <strong>Start</strong> to emulate OBS output as a virtual webcam.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*iD7Zn_syo0gKbK9hNUo9Kw.png" /></figure><h4>Configure Zoom</h4><p>In Zoom, start a meeting, then select a video source. <strong>OBS-Camera</strong> should be available. Select it then click on <strong>Start Video</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/363/1*EoK0OpBR9Oc3zBzX3r4pYg.png" /></figure><p>The Zoom’s video is now OBS Program output.</p><h3>Virtual webcam with NDI 4 Tools</h3><p>Second way to emulate a webcam is to use <strong>NDI</strong> tools and <strong>ndi-obs</strong> plugin. It is a little more tricker to configure but the quality is better.</p><h4>Install NDI 4 Tools</h4><p>Go to <a href="https://ndi.tv/tools/">https://ndi.tv/tools/</a>, and click on Download.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/1*z4ThlOEchcISd3zTdj6NHA.png" /></figure><p>Once downloaded, execute <strong>NDI 4 Tools.exe</strong> file.</p><p>During the installation you can select NDI components. Make sure <strong>Virtual Input</strong> is selected, others are optional.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*J9O_q4psnoAmAUJ75zUBYg.png" /></figure><h4>Install ndi-obs plugin</h4><p>Go to <a href="https://obsproject.com/forum/resources/obs-ndi-newtek-ndi%E2%84%A2-integration-into-obs-studio.528/">https://obsproject.com/forum/resources/obs-ndi-newtek-ndi%E2%84%A2-integration-into-obs-studio.528/</a> and click on <strong>Go to download</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tkvoR1dob6rs4tUKTZc4fQ.png" /></figure><p>Once downloaded, execute <strong>obs-ndi-4.9.0-Windows-Installer.exe</strong> file. Make sure all components are selected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*iSr0DU9nFBBqYa7TPAnKIA.png" /></figure><h4>Configure OBS</h4><p>Start OBS software.</p><p>In the Tools menu, <strong>NDI Output settings </strong>should be available. Click on <strong>NDI Output settings</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*fjBc_fn53rEyTe1RkxBL5w.png" /></figure><p>Make sure <strong>Main Output</strong> is selected and click <strong>OK</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*kSFEpq6iDtTgzh_SF7AaQw.png" /></figure><h4>Configure NDI</h4><p>Start <strong>Virtual Input</strong> application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/1*in5hEUZGWE_UUUtpiEUDmw.png" /></figure><p>On the Windows toolbar systray, Virtual Input should be launched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/117/1*RnrJH5_Dh1wYDiF8UwSA1Q.png" /></figure><p>Right click on <strong>Virtual Input</strong> icon, click on the computer name and select <strong>OBS</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*7shRWpsCtaN5_E_dYJByNg.png" /></figure><h4>Configure Zoom</h4><p>In Zoom, start a meeting, then select a video source. <strong>NewTek NDI Video </strong>should be available. Select it then click on <strong>Start Video</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*afd6v5D3FaEhJKEKXCdNZQ.png" /></figure><p>The Zoom’s video is now OBS Program output.</p><h3>Conclusion</h3><p>It is easy to use OBS to live stream on Zoom with both plugins, but it might be better to use NDI for greater quality.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72b23aa9721a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Example of JSON REST API for ESP32]]></title>
            <link>https://phoax.medium.com/example-of-json-rest-api-for-esp32-4a5f64774a05?source=rss-22cf49bfeb3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a5f64774a05</guid>
            <category><![CDATA[esp32]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Phoax]]></dc:creator>
            <pubDate>Wed, 01 Apr 2020 22:34:38 GMT</pubDate>
            <atom:updated>2020-04-02T19:35:27.040Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*23AvNONOY3Hel1UsJUvv3Q.png" /></figure><h3>Example of JSON REST API on ESP32</h3><p>JSON is a good standard for data exchange. It can be useful to dialog with an ESP32 calling it with a JSON API, and getting its responses in JSON as well.</p><p>Here is one way to do it.</p><p>It has been developed with Visual Code and Platform.io plugin and based on <a href="https://github.com/me-no-dev/ESPAsyncWebServer">https://github.com/me-no-dev/ESPAsyncWebServer</a> library.</p><h3>Create the API</h3><p>Start a blank <strong><em>main.cpp</em></strong> file, and add these following lines.</p><p>Import libraries:</p><pre>#include &lt;Arduino.h&gt;<br>#include &lt;WiFi.h&gt;<br>#include &lt;ESPAsyncWebServer.h&gt;<br>#include &quot;AsyncJson.h&quot;<br>#include &quot;ArduinoJson.h&quot;</pre><p>Start the local server on port 80:</p><pre>AsyncWebServer server(80);</pre><p>Set the current network Wifi access. The two defaults values have to be replaced by real ones:</p><pre>const char *ssid = &quot;<strong><em>NameOfNetwork</em></strong>&quot;;<br>const char *password = &quot;<strong><em>SecurityPassword</em></strong>&quot;;</pre><p>Create a route for not found pages:</p><pre>void notFound(AsyncWebServerRequest *request)<br>{<br>  request-&gt;send(404, &quot;application/json&quot;, &quot;{\&quot;message\&quot;:\&quot;Not found\&quot;}&quot;);<br>}</pre><p>Start the setup by enabling the serial and start Wifi connection:</p><pre>void setup()<br>{<br>  Serial.begin(9600);<br>  WiFi.mode(WIFI_STA);<br>  WiFi.begin(ssid, password);<br>  while (WiFi.waitForConnectResult() != WL_CONNECTED)<br>  {<br>    Serial.printf(&quot;WiFi Failed!\n&quot;);<br>  }</pre><p>Once connected, display the ESP32 IP address, it will be used to send request:</p><pre>Serial.print(&quot;IP Address: &quot;);<br>Serial.println(WiFi.localIP());</pre><p>Create a simple GET route on /. The response is a JSON in a string:</p><pre>server.on(&quot;/&quot;, HTTP_GET, [](AsyncWebServerRequest *request) {<br>  request-&gt;send(200, &quot;application/json&quot;, &quot;{\&quot;message\&quot;:\&quot;Welcome\&quot;}&quot;);<br>});</pre><p>Create a GET route with params on /get-message. The response is a JSON object converted in a string:</p><pre>server.on(&quot;/get-message&quot;, HTTP_GET, [](AsyncWebServerRequest *request) {<br>  StaticJsonDocument&lt;100&gt; data;<br>  if (request-&gt;hasParam(&quot;message&quot;))<br>  {<br>    data[&quot;message&quot;] = request-&gt;getParam(&quot;message&quot;)-&gt;value();<br>  }<br>  else {<br>    data[&quot;message&quot;] = &quot;No message parameter&quot;;<br>  }<br>  String response;<br>  serializeJson(data, response);<br>  request-&gt;send(200, &quot;application/json&quot;, response);<br>});</pre><p>Create a POST route receiving JSON data in parameters. Data has to be converted depending on the JSON <em>object </em>or <em>array </em>type. The response is the JSON object sent, converted in a string:</p><pre>AsyncCallbackJsonWebHandler *handler = new AsyncCallbackJsonWebHandler(&quot;/post-message&quot;, [](AsyncWebServerRequest *request, JsonVariant &amp;json) {<br>  StaticJsonDocument&lt;200&gt; data;<br>  if (json.is&lt;JsonArray&gt;())<br>  {<br>    data = json.as&lt;JsonArray&gt;();<br>  }<br>  else if (json.is&lt;JsonObject&gt;())<br>  {<br>    data = json.as&lt;JsonObject&gt;();<br>  }<br>  String response;<br>  serializeJson(data, response);<br>  request-&gt;send(200, &quot;application/json&quot;, response);<br>  Serial.println(response);<br>});<br>server.addHandler(handler);</pre><p>Add a handler for not existing routes:</p><pre>server.onNotFound(notFound);</pre><p>Start the server and close the init method:</p><pre>  server.begin();<br>}</pre><p>Add the loop method for future use:</p><pre>void loop()<br>{}</pre><p>The code can now be uploaded to the ESP32. When started it should display the following message from serial monitoring:</p><pre>IP Address: <strong><em>xxx.xxx.xxx.xxx.xxx</em></strong></pre><p>With xxx.xxx.xxx.xxx the current IP address of the ESP32.</p><h3>Full code</h3><pre>#include &lt;Arduino.h&gt;<br>#include &lt;WiFi.h&gt;<br>#include &lt;ESPAsyncWebServer.h&gt;<br>#include &quot;AsyncJson.h&quot;<br>#include &quot;ArduinoJson.h&quot;<br>AsyncWebServer server(80);<br>const char *ssid = &quot;NameOfNetwork&quot;;<br>const char *password = &quot;SecurityPassword&quot;;<br>void notFound(AsyncWebServerRequest *request)<br>{<br>  request-&gt;send(404, &quot;application/json&quot;, &quot;{\&quot;message\&quot;:\&quot;Not found\&quot;}&quot;);<br>}<br>void setup()<br>{<br>  Serial.begin(9600);<br>  WiFi.mode(WIFI_STA);<br>  WiFi.begin(ssid, password);<br>  while (WiFi.waitForConnectResult() != WL_CONNECTED)<br>  {<br>    Serial.printf(&quot;WiFi Failed!\n&quot;);<br>  }<br>  Serial.print(&quot;IP Address: &quot;);<br>  Serial.println(WiFi.localIP());</pre><pre>server.on(&quot;/&quot;, HTTP_GET, [](AsyncWebServerRequest *request) {<br>    request-&gt;send(200, &quot;application/json&quot;, &quot;{\&quot;message\&quot;:\&quot;Welcome\&quot;}&quot;);<br>  });<br>  server.on(&quot;/get-message&quot;, HTTP_GET, [](AsyncWebServerRequest *request) {<br>    StaticJsonDocument&lt;100&gt; data;<br>    if (request-&gt;hasParam(&quot;message&quot;))<br>    {<br>      data[&quot;message&quot;] = request-&gt;getParam(&quot;message&quot;)-&gt;value();<br>    }<br>    else<br>    {<br>      data[&quot;message&quot;] = &quot;No message parameter&quot;;<br>    }<br>    String response;<br>    serializeJson(data, response);<br>    request-&gt;send(200, &quot;application/json&quot;, response);<br>  });<br>  AsyncCallbackJsonWebHandler *handler = new AsyncCallbackJsonWebHandler(&quot;/post-message&quot;, [](AsyncWebServerRequest *request, JsonVariant &amp;json) {<br>    StaticJsonDocument&lt;200&gt; data;<br>    if (json.is&lt;JsonArray&gt;())<br>    {<br>      data = json.as&lt;JsonArray&gt;();<br>    }<br>    else if (json.is&lt;JsonObject&gt;())<br>    {<br>      data = json.as&lt;JsonObject&gt;();<br>    }<br>    String response;<br>    serializeJson(data, response);<br>    request-&gt;send(200, &quot;application/json&quot;, response);<br>    Serial.println(response);<br>  });<br>  server.addHandler(handler);</pre><pre>server.onNotFound(notFound);<br>  server.begin();<br>}</pre><pre>void loop()<br>{<br>}</pre><h3>Testing</h3><p>When started, the ESP32 should display its IP address, for example.</p><p><strong><em>IP Address: 192.168.4.8</em></strong></p><p>This IP address is used to make the request. Here is curl commands to test the ESP32 API.</p><h4>Test / route</h4><pre>curl -i -X GET http://192.168.4.8/</pre><p>Should return:</p><pre>HTTP/1.1 200 OK<br>Content-Length: 21<br>Content-Type: application/json<br>Connection: close<br>Accept-Ranges: none</pre><pre>{&quot;message&quot;:&quot;Welcome&quot;}</pre><h4>Test /get-message route with a param</h4><pre>curl -i -X GET http://192.168.4.8/get-message?message=HelloServer</pre><p>Should return:</p><pre>HTTP/1.1 200 OK<br>Content-Length: 25<br>Content-Type: application/json<br>Connection: close<br>Accept-Ranges: none</pre><pre>{&quot;message&quot;:&quot;HelloServer&quot;}</pre><h4>Test /post-message route with data</h4><pre>curl -i -d &#39;{&quot;message&quot;:&quot;My sample data&quot;}&#39;  -H &quot;Content-Type: application/json&quot;  -X POST http://192.168.4.8/post-message</pre><p>Should return:</p><pre>HTTP/1.1 200 OK<br>Content-Length: 28<br>Content-Type: application/json<br>Connection: close<br>Accept-Ranges: none</pre><pre>{&quot;message&quot;:&quot;My sample data&quot;}</pre><h3>Conclusion</h3><p>The ESP32 can now be queried with GET requests and JSON POST requests and responds with JSON data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a5f64774a05" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Start an Ethereum Node on a Raspberry Pi 4 with Geth]]></title>
            <link>https://phoax.medium.com/start-an-ethereum-node-on-a-raspberry-pi-4-with-geth-ba13d9f57ef8?source=rss-22cf49bfeb3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba13d9f57ef8</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[geth]]></category>
            <category><![CDATA[mainnet]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Phoax]]></dc:creator>
            <pubDate>Sat, 10 Aug 2019 19:23:52 GMT</pubDate>
            <atom:updated>2020-12-08T21:39:53.885Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hYRgMrCNPMxutiuGHvgRvw.png" /></figure><p>In this article, we will see how to install and use the Ethereum client Geth on a Raspberry Pi 4.</p><h3>Requirements</h3><p>Material needed:</p><ul><li>Raspberry Pi 4B, 4 GB RAM (not tested yet on a 2 GB and 1 GB).</li><li>32 Go SD Card.</li></ul><p>Recommended software:</p><p>Download Raspbian Buster Lite: <a href="https://www.raspberrypi.org/downloads/raspbian/">https://www.raspberrypi.org/downloads/raspbian/</a></p><p>Download and install Etcher: <a href="https://www.balena.io/etcher/">https://www.balena.io/etcher/</a></p><h3>Prepare the Raspberry Pi 4</h3><p>First the Raspberry Pi has to be installed and configured. If you like to test your own configuration, you can go to the next chapter.</p><h4>Install SD Card</h4><p><em>Be careful, your SD Card will be formatted.</em></p><ul><li>Mount the downloaded Raspbian image on Etcher.</li><li>Chose the SD Car device.</li><li>Click on Flash!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*CaCa5pw2Btg6yIX_o4Os1g.png" /></figure><p>Once finished, unmount and unplug the SD Card. Plug it in the Raspberry Pi, then power on the Raspberry Pi.</p><h4>Configure the Raspberry Pi</h4><p><strong>Login</strong></p><p>Once booted, the Raspbian lite will prompt a command line access.<br>Default credentials are:<br>Login: <strong>pi</strong><br>Password: <strong>raspberry</strong></p><p><em>For security it is highly recommended to change the password if you plan to have a long term use of your node.</em></p><p><strong>Use the whole SD Card capacity</strong></p><p>Go to <em>raspi-config</em> tool to configure the Raspberry Pi:</p><pre>$ sudo raspi-config</pre><p>Go to the Filesystem options:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*yOq9Fsp9wGIG68_RdBYBTg.png" /></figure><pre>7 Advanced Options &gt; A1 Expand Filesystem &gt; Ok</pre><p>Then, reboot:</p><pre>Finish &gt; Yes</pre><h3>Install Geth client</h3><p>Next, the Geth client has to be installed to start the blockchain synchronization.</p><h4>Install Golang</h4><p>Firstly, Go is required to run Geth (which means Go Ethereum…).</p><p>Get Go and install from sources:</p><pre>$ cd /tmp<br>$ wget <a href="https://storage.googleapis.com/golang/go1.10.1.linux-armv6l.tar.gz">https://storage.googleapis.com/golang/go1.10.1.linux-armv6l.tar.gz</a><br>$ sudo tar -C /usr/local -xzf go1.10.1.linux-armv6l.tar.gz</pre><p>Add <em>/usr/local/go/bin</em> to the PATH environment variable:</p><pre>$ sudo nano /etc/profile</pre><p>Add at the end of the file:</p><pre># Golang<br>export GOROOT=/usr/local/go<br>export GOPATH=$HOME/go<br>export PATH=$PATH:$GOROOT/bin</pre><p>Disconnect/reconnect your session. To test if Go is properly installed execute:</p><pre>$ go version<br><em>go version go1.10.1 linux/arm</em></pre><h4>Install Geth</h4><p>Go to <a href="https://geth.ethereum.org/downloads/">https://geth.ethereum.org/downloads/</a> to get the last <em>arm7 </em>version, and extract the archive:</p><pre>$ cd /tmp<br>$ wget <a href="https://gethstore.blob.core.windows.net/builds/geth-linux-arm7-1.9.1-b7b2f60f.tar.gz">https://gethstore.blob.core.windows.net/builds/geth-linux-arm7-1.9.1-b7b2f60f.tar.gz</a><br>$ tar -zxvf geth-linux-arm7-1.9.1-b7b2f60f.tar.gz</pre><p>Add the program into <em>/usr/local/bin</em>:</p><pre>$ cd geth-linux-arm7-1.9.1-b7b2f60f/<br>$ sudo mv geth /usr/local/bin/</pre><p>Disconnect/reconnect your session. To test if Geth is successfully installed execute:</p><pre>$ geth version<br><em>Geth<br>Version: 1.9.1-stable<br>[…]</em></pre><h3>Run Geth client on Mainnet</h3><h4>Blockchain synchronization</h4><p>Geth runs with options (<a href="https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options">https://github.com/ethereum/go-ethereum/wiki/Command-Line-Options</a>). In order to simply synchronize the Raspberry Pi with the Mainnet blockchain, execute:</p><pre>$ geth --cache=218 --syncmode &quot;light&quot;</pre><p><strong>cache </strong>option is important to avoid fatal memory error fatal (i.e “fatal error runtime out of memory”).</p><p><strong>syncmode </strong>options are “fast”, “full” and “light” (<a href="https://docs.ethhub.io/using-ethereum/running-an-ethereum-node/">https://docs.ethhub.io/using-ethereum/running-an-ethereum-node/</a>). Only light syncmode should be working. With fast the node is always behind ( <a href="https://github.com/ethereum/go-ethereum/issues/16796">https://github.com/ethereum/go-ethereum/issues/16796</a>).</p><p>It should take several minutes to synchronize…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cPz2KigSfEREWesnLVg6nw.png" /></figure><h4>Allow RPC</h4><p>With the command line above, the Node is not accessible in RPC. To open RPC communication, execute:</p><pre>$ geth --cache=128 --syncmode &quot;light&quot; --rpc --rpcaddr 0.0.0.0</pre><p><strong>rpc </strong>enable the HTTP-RPC server.</p><p><strong>rpcaddr 0.0.0.0</strong> allow other computers on the network to connect to Geth server.</p><p>The node is now accessible on <strong>http://&lt;<em>rp4_ip_address</em>&gt;:8545</strong></p><p>The <em>rp4_ip_address </em>is accessible with <em>ip</em> command:</p><pre>$ ip addr<br>[...]<br>2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq state UP group default qlen 1000<br>    [...]<br>    inet <strong>192.168.1.20</strong>/24 brd 192.168.1.255 scope global noprefixroute eth0<br>[...]</pre><p>In this example, the eth0 IP is <strong>192.168.1.20</strong>.</p><p>You can use <a href="https://metamask.io/">https://metamask.io/</a> to test the node connection.</p><ul><li>Select Custom RPC Network.</li><li>Add your node name and settings and save.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*AlRvqT66LvnaVUFnQjeVqA.png" /></figure><p>Metamask should be connected to the Ethereum Mainnet blockchain through your Raspberry Pi node:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/359/1*xjlLpdAKK6bHG-EDkU_xrQ.png" /></figure><h3>Run Geth client on Ropsten Testnet</h3><h4>Blockchain synchronization</h4><p>To develop, Ropsten is used instead of the Mainnet. To synchronize with the Ropsten Testnet, execute:</p><pre>$ geth --testnet --cache=128 --syncmode &quot;light&quot; --rpc --rpcaddr 0.0.0.0</pre><p><strong>testnet </strong>enable the pre-configured proof-of-work test network.</p><p>It should also take several minutes to synchronize…</p><h3>Remove blockchains</h3><p>It might be helpful to remove/reset one or the other blockchain.</p><p>To remove Mainnet blockchain and state databases, execute:</p><pre>geth removedb</pre><p>To remove Ropsten Testnet blockchain and state databases, execute:</p><pre>geth --testnet removedb</pre><h3>Conclusion</h3><p>The Raspberry Pi 4 has just been released. It has more power and RAM, but it is still complicated to run full or fast synchronized node. Only light is working well.</p><p>And actually there are three main Ethereum clients: <a href="https://geth.ethereum.org/">Geth</a>, <a href="https://www.parity.io/ethereum/">Parity</a> and <a href="https://pegasys.tech/">Pantheon</a>. For now, only Geth seems to work fine on a Raspberry Pi.</p><p>The next step should be testing to send transactions with web3:</p><pre>$ geth --testnet --cache=128 --syncmode &quot;light&quot; --rpc --rpcaddr 0.0.0.0 --rpcapi &quot;db,eth,net,web3&quot;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba13d9f57ef8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>