You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,29 +16,10 @@ Note: This whole readme assumes the following environment:
16
16
- You are using the user "Pi" (if you have something else, just replace the username wherever stated)
17
17
- You are using a fresh installation of the OS
18
18
- You are using a USBtin device to connect to the CAN Bus (others might work but are not tested by me)
19
+
- In thoery (and also during development I did this), socketcand and canutils can run the Raspberry Pi while can2mqtt is running on a another device in the network. That way you can also use a Raspberry Pi Zero (1st Gen) for socketcand and can-utils while running can2mqtt on another system that supports the Dotnet Framework (requires ARMv7 or later architecture).
Note, the packagelink may be differnt if you are not using a OS based on ubuntu 21.04 or 21.10. Check this page for other releases: https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu
44
25
This are the links from https://dotnet.microsoft.com/en-us/download/dotnet/6.0 for the differente Processor architectures for Linux:
To add this to autostart and setup the adapter on every reboot, run "sudo nano /etc/rc.local"
66
-
paste three lines above at the end before the "EXIT 0".
56
+
To add this to autostart and setup the adapter on every reboot, run 'sudo nano /etc/rc.local'
57
+
Paste three lines above at the end before the "EXIT 0".
67
58
68
-
## Start socketcand
69
-
This is only required to test or if you like to take care of socketcand on your own. You can also configure a daemon to do this automatically (see below).
This is only required to test or if you like to take care of socketcand on your own.
70
75
You need to replace eth0 if your network interface is called different than eth0.
71
76
```
72
77
/opt/socketcand/socketcand -i slcan0 -l eth0 -v
73
78
```
74
79
75
-
## MQTT Broker
76
-
You need an MQTT Broker, that is handling the MQTT Traffic. You need to define this in the settings.
77
-
78
-
## Start can2mqtt:
79
-
This is only required to test or if you like to take care of can2mqtt on your own. You can also configure a daemon to do this automatically (see below).
|`--Daemon:Name`| Define the name of your Daemon | Can2Mqtt | No |`--Daemon:Name="Can2MqttSE"`|
90
-
|`--Daemon:CanServer`| This is the address where your canlogserver is running | 127.0.0.1 | No |`--Daemon:CanServer="192.168.0.192"`|
91
-
|`--Daemon:CanServerPort`| This is the port of the canlogserver | 28700 | No |`--Daemon:CanServerPort=28700`|
92
-
|`--Daemon:MqttServer`| This is the address of the MQTT Broker. || Yes |`--Daemon:MqttServer="192.168.0.192"`|
93
-
|`--Daemon:MqttClientId`| This is the clientId of the MQTT Client. Choose any name you like | Can2Mqtt | No |`--Daemon:MqttClientId="Can2Mqtt"`|
94
-
|`--Daemon:MqttTopic`| This is the MQTT Root Topic of all MQTT message | Can2Mqtt | No |`--Daemon:MqttTopic="Heating"`|
95
-
|`--Daemon:MqttTranslator`| For some CAN Bus Clients are translators to translate the CAN Messages into a readable value and publish them via MQTT including the correct topic. Leave empty to publish every CAN frame without any further handling. Implemented translators right now: StiebelEltron || No |`--Daemon:MqttTranslator="StiebelEltron"`|
96
-
|`--Daemon:CanForwardWrite`| Should CAN frames of type "Write" be forwarded to MQTT? | true | No |`--Daemon:CanForwardWrite=true`|
97
-
|`--Daemon:CanForwardRead`| Should CAN frames of type "Read" be forwarded to MQTT? | false | No |`--Daemon:CanForwardRead=false`|
98
-
|`--Daemon:CanForwardResponse`| Should CAN frames of type "Response" be forwarded to MQTT? | true | No |`--Daemon:CanForwardResponse=true`|
99
-
100
-
101
-
## Configure and Register Daemon for can2mqtt and canlogserver
102
-
Execute `sudo nano /etc/systemd/system/canlogserver.service` and paste the following into the file. Replace the slcan0 in case your socket has a different name:
80
+
### Setup socketcand as daemon
81
+
Execute 'sudo nano /etc/systemd/system/socketcand.service', replace the network interface name if it is not eth0, replace the user with a username the daemon will use to run and paste the following:
Run `sudo systemctl start canlogserver.service` to test if the service starts (it should). To see if it runs, execute `sudo systemctl status canlogserver.service`. You should see something similar like this if everything went well in the last line: `Jul 03 19:09:16 raspi-test systemd[1]: Started canlogserver.`
120
98
121
-
Now we repeat this for the can2mqtt daemon. Execute `sudo nano /etc/systemd/system/can2mqtt.service` and paste the following into the file. Replace the placeholder with your parameters:
99
+
Finally run the following commands:
100
+
```
101
+
sudo systemctl enable socketcand
102
+
sudo systemctl start socketcand
103
+
```
104
+
105
+
## MQTT Broker
106
+
You need an MQTT Broker, that is handling the MQTT Traffic. You need to define the MQTT Broker IP in the can2mqtt config file later.
107
+
If you don't have any MQTT broker, Mosquitto is a common MQTT Broker.
108
+
109
+
## can2mqtt
110
+
### Download can2mqtt
111
+
wget <Latest release at https://github.com/Hunv/can2mqtt/releases> -O can2mqtt.zip
112
+
sudo unzip can2mqtt.zip /opt/can2mqtt
113
+
114
+
### Start can2mqtt:
115
+
Optional: This is only required to test or if you like to take care of can2mqtt on your own by running can2mqtt interactivly.
116
+
You can also configure a daemon to do this automatically (see below).
117
+
```
118
+
dotnet /opt/can2mqtt/can2mqtt
119
+
```
120
+
121
+
### Setup can2mqtt as daemon
122
+
Execute 'sudo nano /etc/systemd/system/can2mqtt.service', replace the network interface name if it is not eth0, replace the user with a username the daemon will use to run and paste the following:
122
123
```
123
124
[Unit]
124
125
Description=can2mqtt
125
126
After=network.target
126
127
127
128
[Service]
128
-
ExecStart=/usr/local/bin/dotnet /home/pi/can2mqtt_core/can2mqtt_core.dll >>>STATE YOUR PARAMETERS HERE<<<
To test if it works, run the following command: `sudo systemctl start can2mqtt.service`. To test if the service is running, execute `sudo systemctl status can2mqtt.service`. You will see the last lines of output. If you do not see any errors after about 10 seconds, everything is fine.
140
+
Finally run the following commands:
141
+
```
142
+
sudo systemctl enable can2mqtt
143
+
sudo systemctl start can2mqtt
144
+
```
142
145
143
-
Finally if everything is fine and you want to autostart the canlogserver and can2mqtt application, execute this:
146
+
### Configure config.json:
147
+
First copy the sample config.json file: 'sudo cp /opt/can2mqtt/config-sample.json /opt/can2mqtt/config.json'
148
+
Edit the config.json with your favorite editor (i.e. nano): 'sudo nano /opt/can2mqtt/config.json'
144
149
```
145
-
sudo systemctl enable canlogserver.service
146
-
sudo systemctl enable can2mqtt.service
147
-
```
150
+
{
151
+
"CanServer": "192.168.0.10", < This is the System where socketcand is running on
152
+
"CanServerPort": 29536, < This is the port socketcand is using (29536 is default)
153
+
"CanForwardWrite": true, < This defines if can2mqtt will handle CAN bus packages, that have the "write" flag
154
+
"CanForwardRead": true, < This defines if can2mqtt will handle CAN bus packages, that have the "read" flag
155
+
"CanForwardResponse": true, < This defines if can2mqtt will handle CAN bus packages, that have the "response" flag
156
+
"CanReceiveBufferSize": 48, < The buffer size of receiving commands. 48 is default.
157
+
"CanSenderId":"6A2", < The ID can2mqtt will use at the CAN bus in case of writing to the CAN bus
158
+
159
+
"MqttServer": "192.168.0.10", < This is the IP of the MQTT Broker
160
+
"MqttClientId": "Can2Mqtt", < This is the ID the MQTT Client will use when register at MQTT Broker
161
+
"MqttTopic": "Heating", < This is the first path item of the MQTT topic path can2mqtt will use for send/receive information
162
+
"MqttTranslator": "StiebelEltron",< This is the translator used to translate the CAN bus data to values and send it via MQTT
163
+
"MqttUser": "", < This is the user that is required to register at the MQTT broker. Leave empty for none.
164
+
"MqttPassword": "", < This is the password that is required to register at the MQTT broker. Leave empty for none.
165
+
"MqttAcceptSet": false, < This is a setting, that defines if can2mqtt will send write-commands to the CAN bus. For safety reasons the default setting is set to false.
166
+
167
+
"NoUnits": false < This defines if sending MQTT messages will contain the unit defined in the translator config or not (i.e. "25°C" or just "25")
168
+
}
169
+
```
170
+
171
+
# MQTT Data format
172
+
can2mqtt sends the data in the topics, that are defined in the config of the translator. In case of the Stiebel Eltron translator it is the 'StiebelEltron.json'. There will be a prefix-topic in case there are other instances of can2mqtt or other MQTT applications. This one is configured in the config.json at the setting 'MqttTopic'.
173
+
An example MQTT message may look like this:
174
+
Topic: heating/outside/temperature/measured
175
+
Value: 21°C
176
+
177
+
If you like to set data, add a /set at the end of the topic.
178
+
An example MQTT message to can2mqtt to set the desired room temperature of the primary heat cycle to 23°C:
0 commit comments