* luarocks : ``sudo apt install luarocks``
* busted : ``sudo luarocks install busted``
* python3 : ``sudo apt install python3``
* esptool : ``pip3 install esptool``
* nodemcu-uploader : ``pip3 install nodemcu-uploader``

This page describes the hardware setup for the tallies.
How to build the tallies and how to build and flash new firmware to the tallies.

For the tallies a classic ``RGB`` ledstrip is used instead of the more modern ``WS2812B`` standard. This ledstrip is connected as follows:

In order to build the firmware a ``Toolchain`` for cross compilation is required.
This toolchain is provided in the repository in ``nodemcu-firmware/``.
To build the code for the tallies, navigate to ``wifi-tally/tally/`` and run ``make``.

 for cross compilation is required.
This toolchain is provided in the repository in 

$ make
# if it compiles it is syntactically valid
../../nodemcu-firmware/luac.cross -o /dev/null src/init.lua
"busted"
●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●
91 successes / 0 failures / 0 errors / 0 pending : 0.23373 seconds

To flash the firmware, first put the device in flash mode.
You can do this by pressing and hodling the ``FLASH`` button and presing the ``RST`` button.
After that you can release the ``FLASH`` button.
Next, navigate to ``../wifi-tally/firmware`` and run ``install_firmware.sh``.

You can do this by pressing and hodling the 

$ ./install_firmware.sh
esptool.py v4.4
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 50:02:91:fd:ca:0a
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00070fff...
Flash params set to 0x0020
Compressed 462848 bytes to 301339...
Wrote 462848 bytes (301339 compressed) at 0x00000000 in 26.7 seconds (effective 138.9 kbit/s)...
Hash of data verified.

Leaving...

If you receive an error about permissions, run ``sudo -E ./install_firmware.sh`` to mitigate permissions for the USB device. Also look in the ``troubleshooting`` section if you keep having issues.

Navigate to ``wifi-tally/tally`` and run ``install_application.sh``.

Make sure to edit the ``out/tally-settings.ini`` for the correct wifi SSID and password.

$ ./install_application.sh
opening port /dev/ttyUSB0 with 115200 baud
Preparing esp for transfer.
Transferring out/my-app.lc as out/my-app.lc
Transferring out/my-led.lc as out/my-led.lc
Transferring out/my-log-buffer.lc as out/my-log-buffer.lc
Transferring out/my-log.lc as out/my-log.lc
Transferring out/my-settings.lc as out/my-settings.lc
Transferring out/my-tally.lc as out/my-tally.lc
Transferring out/my-wifi.lc as out/my-wifi.lc
Transferring out/tally-settings.ini as out/tally-settings.ini
All done!

Oostendam Tallies documentation master file, created by
sphinx-quickstart on Mon Jan 23 22:14:59 2023.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

This document contains the documentation for the tallies used in the `Immanuelkapel in Oostendam <https://kerkdienstgemist.nl/stations/2112-Immanuelkapel>`_.
The goal in this project is to provide *cheap* indicator lights to show which camera is active during the service.
This way the minister knows which of the camera's is active and use it during the service.

This document contains the documentation for the tallies used in the 

`Immanuelkapel in Oostendam <https://kerkdienstgemist.nl/stations/2112-Immanuelkapel>`_

 indicator lights to show which camera is active during the service.
This way the minister knows which of the camera’s is active and use it during the service.

This project relies heavily on an `existing project on github <https://github.com/wifi-tally/wifi-tally/>`_.
The main difference between this code and the project on github is the behaviour of the tally lights.

`existing project on github <https://github.com/wifi-tally/wifi-tally/>`_

.

1. Configure the new computer to use the *same* IP address as the previous computer.
2. Install `NodeJS and NPM <https://nodejs.org/en/download>`_
3. Copy the config.json (homedir + .wifi-tally.json) to the same location of the new PC.
4. Run the server on the host PC(see below)

Configure the new computer to use the *same* IP address as the previous computer.

Copy the config.json (homedir + .wifi-tally.json) to the same location of the new PC.

To run the server, navigate to ``wifi-tally/hub`` and execute ``run_server.sh``

$ ./run_server.sh

> wifi-tally-hub@0.1.0 start
> node server.js --env=production

Using mixer configuration "null"
No video mixer connected.
Listening for Tallies on 0.0.0.0:7411
Web Server available on http://localhost:3000
(node:117081) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time

This page gives a short overview of how the tallies work in relation to the camera's. A simple overview of the tallies in correlation between the server and the streamer is shown below:

This page gives a short overview of how the tallies work in relation to the camera’s. A simple overview of the tallies in correlation between the server and the streamer is shown below:

The hardware for the tallies is an ``esp8266`` microcontroller, as they can be found `on Amazon <https://www.amazon.nl/Diymore-ESP8266-WiFi-ontwikkelingskaart-NodeMCU-ESP-12E-module/dp/B09Z6T2XS4/ref=sr_1_2_sspa?__mk_nl_NL=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=3DHTKU7SQKET9&keywords=esp8266&qid=1674509572&sprefix=esp8266%2Caps%2C135&sr=8-2-spons&sp_csd=d2lkZ2V0TmFtZT1zcF9hdGY&psc=1>`_.
These microcontrollers are very cheap but are capable of using the ``802.11 b/g/n`` wifi standard(``IEEE``).

.
These microcontrollers are very cheap but are capable of using the 

Of the 17 GPIO pins available, only 3 are used for the RGB colouring.
Wifi is used for communication between the tallies and a server that will tell the tally to turn on the lights.

On the Host a ``NodeJS`` server is run that opens a websocket on port ``7411``.
This websockets waits for tallies to connect and sends data to them when connected.
The server also connects to the streamer, in our case a ``Black Magic ATEM`` that controls the camera's.
The streamer gives information about which camera is active which is passed to the tallies.

.
The server also connects to the streamer, in our case a 

 that controls the camera’s.

This section describes the patches made to the software. These patches are provided in the repository so no user interaction is needed when building the firmware.

* Disable any signal leds on error, like no wifi connected or server not accessble
* Disable green led when on preview

Disable any signal leds on error, like no wifi connected or server not accessble

In order to add these patches the following code was edited in the firmware:

_G.MyLed = {
    signal that nothing is being done
    initial = flashPattern("O", colors.BLUE),
    waitForWifiConnection = flashPattern("Oo", colors.GREEN),
    invalidSettingsFile = flashPattern("OoOoOooooooo", colors.BLUE, 2),
    waitForWifiIp = flashPattern("OoOo", colors.BLUE),
    waitForServerConnection = flashPattern("OoOooo", colors.BLUE),
    onPreview = flashPattern("O", colors.GREEN),
    onAir = flashPattern("O", colors.RED),
    onRelease = flashPattern(".", colors.GREEN, nil, false),
    onUnknown = flashPattern("Oooooooo", colors.BLUE, 2),
    onHighlight = flashPattern("OoOoOoOo", colors.WHITE),
    turnOff = flashPattern("O", colors.BLACK),
}

    initial = flashPattern("O", colors.BLACK),
    waitForWifiConnection = flashPattern("O", colors.BLACK),
    invalidSettingsFile = flashPattern("O", colors.BLACK),
    waitForWifiIp = flashPattern("O", colors.BLACK),
    waitForServerConnection = flashPattern("O", colors.BLACK),
    onPreview = flashPattern("O", colors.BLACK),
    onRelease = flashPattern("O", colors.BLACK),
    onUnknown = flashPattern("O", colors.BLACK),
    onHighlight = flashPattern("OoOoOoOo", colors.GREEN),
}

Upon each signal the leds will change, but into the BLACK color and into RED when the camera is active.

The tallies require a server that will direct the tallies and figure out the status of the ``BlackMagic ATEM``.

The tallies require a server that will direct the tallies and figure out the status of the 

$ ./build_server.sh

> wifi-tally-hub@0.1.0 build
> next build

Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
info  - Creating an optimized production build
info  - Compiled successfully
info  - Collecting page data
[==  ] info  - Generating static pages (0/1)info  - Finalizing page optimizati
info  - Finalizing page optimization

Page                              Size     First Load JS
┌ λ /                             4.55 kB        94.4 kB
├   /_app                         0 B            59.2 kB
├ ○ /404                          3.01 kB        62.2 kB
├ λ /config                       1.48 kB        91.3 kB
└ λ /tally/[tallyName]            1.48 kB        91.3 kB
+ First Load JS shared by all     59.2 kB
├ chunks/07ed33f3.bca366.js     68 B
├ chunks/commons.94f2cd.js      11 kB
├ chunks/framework.9ec1f7.js    39.9 kB
├ chunks/main.7e5158.js         7.2 kB
├ chunks/pages/_app.627bfb.js   284 B
├ chunks/webpack.e06743.js      751 B
└ css/ba2fd543a36dbb3ceef1.css  25.9 kB

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
(ISR)     incremental static regeneration (uses revalidate in getStaticProps)

[ ===] info  - Generating static pages (0/1)%

Depending on the OS of the stream PC you might need to create a new shell script to execute the **npm run start** command to run the server.

Depending on the OS of the stream PC you might need to create a new shell script to execute the 

If you have issues with the ``esp8266`` not connecting on /dev/ttyUSB, but the device does show up in lsusb:

 not connecting on /dev/ttyUSB, but the device does show up in lsusb:

$ lsusb
[..]
Bus 001 Device 019: ID 1a86:7523 QinHeng Electronics CH340 serial converter
[..]

Then this might be related to a udev rule in Linux.
Removing this rule will stop udev from hijacking the USB device.

sudo rm /usr/lib/udev/rules.d/*-brltty-*.rules
sudo udevadm control --reload-rules
sudo systemctl mask brltty.path

``ESPlorer`` is a tool that allows you to flash firmware to the ESP8266 using a GUI. This is example code on how to build and run it:

 is a tool that allows you to flash firmware to the ESP8266 using a GUI. This is example code on how to build and run it:

git clone https://github.com/4refr0nt/ESPlorer.git

# Build it
./mvnw clean package

# Run it
java -jar target/ESPlorer.jar

The ``ESPlorer`` can be used to interact with the ``esp8266`` and flash binaries using a GUI.