A simple smartmeter which is connected to a S0-interface and counts the energy consumption or provides the current power consumption. The informations can be read via REST-API.
It runs on the Pollin AVR-NET-IO board.
- AVR-NET-IO-Smartmeter
- Motivation
- Usage
- Electronic
- Software
- REST API
- Issues, Ideas And Bugs
- License
- Contribution
The idea was to have a simple way to get the power consumption of the heatpump and the rest of the house. The data shall be provided over a REST-API, which can easily be used from e.g. bash via curl. The data is retrieved periodically, pushed to a influx-database and visualized with grafana.
Up to 8 S0 interface would be possible with the AVR-NET-IO board, but because of RAM limitation only 2 are configured. More may be possible, but that was never verified.
- Connect your S0 signal with the board, see the table in the next chapter.
- Configure S0 interface (0-1) by browsing to http://<device-ip-address>/configure/<s0-interface> with your favorite browser. Replace <s0-interface> with the S0 interface id.
- Configure the S0 interface and enable it.
Note, the AVR-NET-IO has original a ATmega32-16PU, which was replaced with a ATmega644p.
Warning
2024-01-01: The Pollin AVR-NET-IO development is obsolete and not available anymore.
There is no known successor development board.
The following table shows the possible connections for S0 signals.
Terminal | Name | MCU Pin | Arduino Pin |
---|---|---|---|
J3 | Input 1 | PA0 | 24 |
J3 | Input 2 | PA1 | 25 |
J3 | Input 3 | PA2 | 26 |
J3 | Input 4 | PA3 | 27 |
J9 | ADC1 | PA4 | 28 |
J9 | ADC2 | PA5 | 29 |
J7 | ADC3 | PA6 | 30 |
J7 | ADC4 | PA7 | 31 |
The PlatformIO IDE is used for the development. Its build on top of Microsoft Visual Studio Code.
- Install VSCode.
- Install PlatformIO IDE according to this HowTo.
- Close and start VSCode again.
- Recommended is to take a look to the quick-start guide.
Note, for the following steps I used the AtmelStudio v7.0 with my AVR-ISP programmer, because I didn't manage to get this setup work with VSCode + Platformio or the Arduino IDE.
- Set fuse bits: lfuse = 0xf7, hfuse = 0xd6, efuse = 0xfd
- The MightyCore provides in the platformio installation directy bootloaders. Choose
.platformio/packages/framework-arduino-avr-mightycore/bootloaders/optiboot_flash/bootloaders/atmega644p/16000000L/optiboot_flash_atmega644p_UART0_115200_16000000L_B0_BIGBOOT.hex
- If the bootloader is active, two pulses are shown on pin B0 (= Arduino pin 0), which can be checked with a oscilloscope.
After the bootloader is installed and running, the typical Arduino upload can be used over the serial interface.
Every AVR-NET-IO board comes with a unique MAC address of the network interface controller. Before you build the software it is necessary to set it in the sourcecode. Therefore open ./src/main.cpp
in the editor, search for the variable DEVICE_MAC_ADDR
and change it accordingly.
- Load workspace in VSCode.
- Change to PlatformIO toolbar.
- Project Tasks -> Build All or via hotkey ctrl-alt-b
- Connect the AVR-NET-IO board to your PC via serial interface.
- Build and upload the software via Project Tasks -> Upload All.
- Note, if the AVR-NET-IO board is not modified, you need to keep it off until in the console
Uploading .pio\build\MightyCore\firmware.hex
is shown. Just in this moment power the board and the upload starts.
- MightyCore - Arduino core for ATmega644.
- EthernetENC - Ethernet library for ENC28J60 with Arduino compatible interface.
- ArduinoHttpServer - Server side minimalistic object oriented HTTP protocol implementation.
- ArduinoJSON - JSON library.
Get S0 interface data:
- S0 interface unique id.
- S0 interface name.
- The current power consumption in W.
- Number of counted pulses.
- Energy consumption in Wh, depended on the number of counted pulses.
<s0-interface-id>
:
- The S0 interface id is in range [0; 1].
Response:
{
"data": {
"id": 0,
"name": "S0-0",
"pulsesPer1KWh": 1000,
"powerConsumption": 230,
"pulses": 40,
"energyConsumption": 460
},
"status":0
}
Status 0 means successful. If the request fails, it the status will be non-zero and data is empty.
Get data from all S0 interfaces at once.
A S0 interface contains the following data:
- S0 interface unique id.
- S0 interface name.
- The current power consumption in W.
- Number of counted pulses.
- Energy consumption in Wh, depended on the number of counted pulses.
Response:
{
"data": [{
"id": 0,
"name": "S0-0",
"pulsesPer1KWh": 1000,
"powerConsumption": 230,
"pulses": 40,
"energyConsumption": 460
}, {
"id": 1,
"name": "S0-1",
"pulsesPer1KWh": 1000,
"powerConsumption": 50,
"pulses": 20,
"energyConsumption": 100
}],
"status":0
}
Status 0 means successful. If the request fails, it the status will be non-zero and data is empty.
If you have further ideas or you found some bugs, great! Create a issue or if you are able and willing to fix it by yourself, clone the repository and create a pull request.
The whole source code is published under the MIT license. Consider the different licenses of the used third party libraries too!
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, shall be licensed as above, without any additional terms or conditions.