Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8 from bram2202/develop
Browse files Browse the repository at this point in the history
Release of custom PCB
  • Loading branch information
bram2202 authored Jul 1, 2021
2 parents 58ac0e8 + ff893dc commit 382506a
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 64 deletions.
Binary file added PCB/gerber.zip
Binary file not shown.
Binary file added PCB/schematic.pdf
Binary file not shown.
51 changes: 28 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ A ESP8266 based DSMR reader, posting onto MQTT, powered directly from the meter

The code should work on DSRM v2.2 and higher, only tested on V4.2.

![esp8266-dsmr](https://github.com/bram2202/esp8266-dsmr/blob/master/docs/esp8266-dsmr.jpg "esp8266-dsmr")
![esp8266-dsmr](https://github.com/bram2202/esp8266-dsmr/blob/master/docs/PCB_IRL.png "esp8266-dsmr")

## Requirements
* Arduino IDE / VS code
* ESP8266 board (Wemos/LOLIN D1 mini/ESP01/NodeMCU)
* Basic soldering and wiring skills
* (For Wemos d1 mini) CH340G driver [[link]](https://wiki.wemos.cc/downloads)
* Prototype board / breadboard / PCB
* RJ11/12/25 cable

## Library dependencies
- [PubSubClient](https://pubsubclient.knolleary.net) - MQTT client
Expand Down Expand Up @@ -61,7 +63,6 @@ The code should work on DSRM v2.2 and higher, only tested on V4.2.
| timestamp| - | 0-1:24.2.1| <MQTT_TOPIC>/gas/timestamp |
| device id | - | 0-1:96.1.0 | <MQTT_TOPIC>/gas/device |


## Settings
Copy `Settings.example.h` to `Settings.h` and fill in the correct data.

Expand All @@ -81,40 +82,44 @@ Copy `Settings.example.h` to `Settings.h` and fill in the correct data.


## Circuit
view [scheme.pdf](scheme.pdf).
View [scheme (pdf)](pcb/schematic.pdf).

Using a level shifter inverter to get the serial output from the meter into the ESP.<br>
The board is powered directly from the meters power supply.<br>
The board can be powered directly from the meters power supply <i>(this can vary between models)</i>.


## Custom PCB
Create your own with the [Gerber files (zip)](pcb/gerber.zip)

**Flash the firmware before attaching the circuit,** see "know issue"!

### Parts
## PCB case
- TODO

## Parts
| Type | Amount |
|:---|:---|
| ESP8266 | 1 |
| Prototyping board | 1 |
| 2.2k resistor | 2 |
| 1k resistor | 1 |
| BC547 | 1 |
| 470uf cap. | 1 |

### RJ11 connection
| ESP8266 board| 1 |
| Prototyping board or PCB | 1 |
| 2.2k resistor (0805) | 2 |
| 1k resistor (0805) | 1 |
| BC547 or BC817 (SOT-23) | 2 |
| 470uf cap. 8x12mm | 1 |

Connecting to the DSMR witn a RJ11 in Port 1 (P1), found on most smart meters.
## DSMR connection

Connecting to the DSMR with a RJ11/12/25 (6p6c or 6p4c) cable plugged into the Port 1 (P1), found on all supported smart meters.

| DSRM RJ11 | Description | J1 pin |
| DSRM P1 | Description | PCB Pin |
|:---|:---|:---|
| 1 | +5v | 1 (5v) |
| 2 | Request | 2 (5v) |
| 3 | Data GND| 3 (GND) |
| 1* | +5v | 6 (5v) |
| 2 | Request | 5 (5v) |
| 3 | Data GND| 4 (GND) |
| 4 | N.C. | N.C. |
| 5 | Data | 5 (Data)|
| 6 | Power GND | 6 (GND) |
| 5 | Data | 2 (Data)|
| 6* | Power GND | 1 (GND) |

`* 1 and 6 are not needed if powered by USB.`

## Known issues
- If the level shifter inverter is connected, it's impossible to flash the firmware.<br>
Pin RX is used, disconnect the pin to flash new firmware.
- Some DSMR cannot deliver enough power to run the Wemos stably.<br>
Connect a 5V usb supply to fix this.
Binary file added docs/DSMR_bottem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/DSMR_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/PCB_IRL.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 48 additions & 41 deletions esp8266-dsmr.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,36 @@ typedef struct
} Measurement;

const Measurement measurements[] = {
{"version", "1-3:0.2.8", 10, 12, Measurement::STRING},
{"power/timestamp", "0-0:1.0.0", 10, 23, Measurement::STRING},
{"power/device_id", "0-0:96.1.1", 11, 45, Measurement::STRING},
{"power/consuption", "1-0:1.7.0", 10, 16, Measurement::FLOAT},
{"power/production", "1-0:2.7.0", 10, 16, Measurement::FLOAT},
{"power/total_consuption_low", "1-0:1.8.1", 10, 20, Measurement::FLOAT},
{"power/total_consuption_high", "1-0:1.8.2", 10, 20, Measurement::FLOAT},
{"power/total_production_low", "1-0:2.8.1", 10, 20, Measurement::FLOAT},
{"power/total_production_high", "1-0:2.8.2", 10, 20, Measurement::FLOAT},
{"power/power_tariff", "0-0:96.14.0", 12, 16, Measurement::INT},
{"power/short_power_outages", "0-0:96.7.21", 12, 17, Measurement::INT},
{"power/long_power_outages", "0-0:96.7.9", 11, 16, Measurement::INT},
{"power/phase_1/short_power_drops", "1-0:32.32.0", 12, 17, Measurement::INT},
{"power/phase_2/short_power_drops", "1-0:52.32.0", 12, 17, Measurement::INT},
{"power/phase_3/short_power_drops", "1-0:72.32.0", 12, 17, Measurement::INT},
{"power/phase_1/short_power_peaks", "1-0:32.36.0", 12, 17, Measurement::INT},
{"power/phase_2/short_power_peaks", "1-0:52.36.0", 12, 17, Measurement::INT},
{"power/phase_3/short_power_peaks", "1-0:72.36.0", 12, 17, Measurement::INT},
{"power/phase_1/current", "1-0:31.7.0", 11, 14, Measurement::INT},
{"power/phase_2/current", "1-0:51.7.0", 11, 14, Measurement::INT},
{"power/phase_3/current", "1-0:71.7.0", 11, 14, Measurement::INT},
{"power/phase_1/usage", "1-0:21.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_2/usage", "1-0:41.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_3/usage", "1-0:61.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_1/delivery", "1-0:22.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_2/delivery", "1-0:42.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_3/delivery", "1-0:62.7.0", 11, 17, Measurement::FLOAT},
{"gas/total", "0-1:24.2.1", 26, 35, Measurement::FLOAT},
{"gas/device_id", "0-1:96.1.0", 11, 45, Measurement::STRING},
{"gas/timestamp", "0-1:24.2.1", 11, 24, Measurement::STRING},
{"version", "1-3:0.2.8", 10, 12, Measurement::STRING},
{"power/timestamp", "0-0:1.0.0", 10, 23, Measurement::STRING},
{"power/device_id", "0-0:96.1.1", 11, 45, Measurement::STRING},
{"power/consuption", "1-0:1.7.0", 10, 16, Measurement::FLOAT},
{"power/production", "1-0:2.7.0", 10, 16, Measurement::FLOAT},
{"power/total_consuption_low", "1-0:1.8.1", 10, 20, Measurement::FLOAT},
{"power/total_consuption_high", "1-0:1.8.2", 10, 20, Measurement::FLOAT},
{"power/total_production_low", "1-0:2.8.1", 10, 20, Measurement::FLOAT},
{"power/total_production_high", "1-0:2.8.2", 10, 20, Measurement::FLOAT},
{"power/power_tariff", "0-0:96.14.0", 12, 16, Measurement::INT},
{"power/short_power_outages", "0-0:96.7.21", 12, 17, Measurement::INT},
{"power/long_power_outages", "0-0:96.7.9", 11, 16, Measurement::INT},
{"power/phase_1/short_power_drops", "1-0:32.32.0", 12, 17, Measurement::INT},
{"power/phase_2/short_power_drops", "1-0:52.32.0", 12, 17, Measurement::INT},
{"power/phase_3/short_power_drops", "1-0:72.32.0", 12, 17, Measurement::INT},
{"power/phase_1/short_power_peaks", "1-0:32.36.0", 12, 17, Measurement::INT},
{"power/phase_2/short_power_peaks", "1-0:52.36.0", 12, 17, Measurement::INT},
{"power/phase_3/short_power_peaks", "1-0:72.36.0", 12, 17, Measurement::INT},
{"power/phase_1/current", "1-0:31.7.0", 11, 14, Measurement::INT},
{"power/phase_2/current", "1-0:51.7.0", 11, 14, Measurement::INT},
{"power/phase_3/current", "1-0:71.7.0", 11, 14, Measurement::INT},
{"power/phase_1/usage", "1-0:21.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_2/usage", "1-0:41.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_3/usage", "1-0:61.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_1/delivery", "1-0:22.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_2/delivery", "1-0:42.7.0", 11, 17, Measurement::FLOAT},
{"power/phase_3/delivery", "1-0:62.7.0", 11, 17, Measurement::FLOAT},
{"gas/total", "0-1:24.2.1", 26, 35, Measurement::FLOAT},
{"gas/device_id", "0-1:96.1.0", 11, 45, Measurement::STRING},
{"gas/timestamp", "0-1:24.2.1", 11, 24, Measurement::STRING},
};

MQTTPublisher mqttPublisher;
Expand All @@ -66,15 +66,20 @@ bool hasMQTT = false;
bool hasWIFI = false;
Logger logger = Logger("App");

int rxPin = 3;
int lvlPin = 5;

void setup()
{

// Start serial ESP8266 RX port (pin 3)
Serial.begin(115200);
pinMode(3, FUNCTION_0);
pinMode(rxPin, FUNCTION_0); // RX

logger.info("Booting");
logger.info("Start setup");

pinMode(lvlPin, OUTPUT); // D1
digitalWrite(lvlPin, HIGH); // Turn on RX Trans

// Setup Wifi
wifiConnector = WifiConnector();
wifiConnector.start();
Expand All @@ -86,6 +91,8 @@ void setup()
// Setup OTA
ArduinoOTA.setHostname(WIFI_HOSTNAME);
ArduinoOTA.begin();

logger.info("Setup complte");
}

void loop()
Expand Down Expand Up @@ -126,14 +133,14 @@ void handleString(String incomingString)

switch (measurement.valueType)
{
case Measurement::FLOAT:
value = String(value.toFloat(), 3);
break;
case Measurement::INT:
value = String(value.toInt());
break;
default:
break;
case Measurement::FLOAT:
value = String(value.toFloat(), 3);
break;
case Measurement::INT:
value = String(value.toInt());
break;
default:
break;
}

mqttPublisher.publishOnMQTT(measurement.name, value);
Expand Down
Binary file removed scheme.pdf
Binary file not shown.

0 comments on commit 382506a

Please sign in to comment.