Hi there,
I’m trying to code a Parser for sensors. The Compiler throws following error:
CompileError: Not allowed keyword :parse_vbat on line 149; CompileError: Not allowed keyword :parse_light on line 136; CompileError: Not allowed keyword :parse_flow on line 123; CompileError: Not allowed keyword :parse_db on line 109; CompileError: Not allowed keyword :parse_atmp on line 96; CompileError: Not allowed keyword :parse_voc on line 83; CompileError: Not allowed keyword :parse_rhum on line 69; CompileError: Not allowed keyword :parse_co on line 56; CompileError: Not allowed keyword :parse_temperature on line 43; CompileError: Not allowed keyword :parsepayload on line 19
I dont’t know how to fix it? I’ve tried some other function names but it doesn’t work …
Maybe someone can help me to fix it?
Thanks,
Julian
defmodule Parser do
use Platform.Parsing.Behaviour
require Logger
end
# LPP_TEMP (Devicetype 0x0010)
defp parse_payload(
device_type,
0x01,
<<temperature::signed-16>>
)
when device_type in [0x0010] do
%{
temperature: temperature * 10
}
|> Map.merge(parse_temperature(temperature))
end
# LPP_CO2 (Devicetype 0x0012)
defp parse_payload(
device_type,
0x01,
<<CO2::signed-16>>
)
when device_type in [0x0012] do
%{
CO2: CO2 / 1
}
|> Map.merge(parse_co(CO2))
end
# LPP_RHUM (Devicetype 0x0011)
defp parse_payload(
device_type,
0x01,
<<LLP_RHUM::signed-8>>
)
when device_type in [0x0011] do
%{
LLP_RHUM: LLP_RHUM
}
|> Map.merge(parse_rhum(LLP_RHUM))
end
# LPP_VOC (Devicetype 0x0013)
defp parse_payload(
device_type,
0x01,
<<LLP_VOC::signed-16>>
)
when device_type in [0x0013] do
%{
LLP_VOC: LLP_VOC
}
|> Map.merge(parse_voc(LLP_VOC))
end
# LPP_ATM_P (Devicetype 0x0030)
defp parse_payload(
device_type,
0x01,
<<LLP_ATM::signed-16>>
)
when device_type in [0x0030] do
%{
LPP_ATM_P: LPP_ATM_P
}
|> Map.merge(parse_atmp(LPP_ATM_P))
end
# LPP_DP (Devicetype 0x0031)
defp parse_payload(
device_type,
0x01,
<<LLP_ATM::signed-16>>
)
when device_type in [0x0031] do
%{
LPP_DP: LPP_DP
}
|> Map.merge(parse_db(LPP_DP))
end
# LPP_FLOW (Devicetype 0x0032)
defp parse_payload(
device_type,
0x01,
<<LLP_ATM::signed-16>>
)
when device_type in [0x0032] do
%{
LPP_FLOW: LPP_FLOW
}
|> Map.merge(parse_flow(LPP_FLOW))
end
# LPP_VISIBLE_LIGHT (Devicetype 0x0040)
defp parse_payload(
device_type,
0x01,
<<LLP_ATM::signed-16>>
)
when device_type in [0x0040] do
%{
LPP_VISIBLE_LIGHT: LPP_VISIBLE_LIGHT
}
|> Map.merge(parse_light(LPP_VISIBLE_LIGHT))
end
# LPP_VBAT (Devicetype 0x0054)
defp parse_payload(
device_type,
0x01,
<<LLP_ATM::signed-8>>
)
when device_type in [0x0054] do
%{
LPP_VBAT: LPP_VBAT
}
|> Map.merge(parse_vbat(LPP_VBAT))
end
defp parse_temperature(<<temperature::signed-16>>, field \\ :temperature, factor \\ 0.10) do
%{
field => temperature * factor
}
end
defp parse_co(<<CO2::signed-16>>, field \\ :CO2, factor \\ 1.0) do
%{
field => CO2 * factor
}
end
defp parse_rhum(<<LLP_RHUM::signed-8>>, field \\ :LLP_RHUM, factor \\ 1.0) do
%{
field => LLP_RHUM * factor
}
end
defp parse_voc(<<LLP_VOC::signed-16>>, field \\ :LLP_VOC, factor \\ 1.0) do
%{
field => LLP_VOC * factor
}
end
defp parse_atmp(<<LPP_ATM_P::signed-16>>, field \\ :LPP_ATM_P, factor \\ 1.0) do
%{
field => LPP_ATM_P * factor
}
end
defp parse_dp(<<LPP_DP::signed-16>>, field \\ :LPP_DP, factor \\ 1.0) do
%{
field => LPP_DP * factor
}
end
defp parse_flow(<<LPP_FLOW::signed-16>>, field \\ :LPP_FLOW, factor \\ 1.0) do
%{
field => LPP_FLOW * factor
}
end
defp parse_light(<<LPP_VISIBLE_LIGHT::signed-16>>, field \\ :LPP_VISIBLE_LIGHT, factor \\ 1.0) do
%{
field => LPP_VISIBLE_LIGHT * factor
}
end
defp parse_vbat(<<LPP_VBAT::signed-8>>, field \\ :LPP_VBAT, factor \\ 0.05) do
%{
field => LPP_VBAT * factor
}
end
def fields() do
[
%{
field: "temperature",
display: "Temperatur",
unit: "°C"
},
%{
field: "CO2",
display: "CO2",
unit: "ppm"
},
%{
field: "LLP_RHUM",
display: "relative Feuchte",
unit: "% rH"
},
%{
field: "LLP_VOC",
display: "VOC",
unit: "%"
},
%{
field: "LLP_ATM_P",
display: "Absoluter Druck",
unit: "mBar/hPa"
},
%{
field: "LLP_DP",
display: "Differenzdruck",
unit: "Pa"
},
%{
field: "LLP_FLOW",
display: "Volumenstrom",
unit: "m3/h"
},
%{
field: "LPP_VISIBLE_LIGHT",
display: "Beleuchtungsstärke",
unit: "lux"
},
%{
field: "LPP_VBAT",
display: "Energielevel",
unit: "mV"
}
]
end