-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathluaParseJsonSimple.xml
More file actions
72 lines (66 loc) · 2.6 KB
/
luaParseJsonSimple.xml
File metadata and controls
72 lines (66 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<project name="lua_parse_simple" pubsub="auto" threads="4" heartbeat-interval="1" luaroot="@ESP_PROJECT_OUTPUT@/luaroot">
<description><![CDATA[This project uses a Lua window to parse JSON data from a CSV file to generate events.]]></description>
<metadata>
<meta id="layout">{"cq":{"CreateMulti":{"x":50,"y":175},"Source":{"x":50,"y":50}}}</meta>
<meta id="studioTags">Example</meta>
<meta id="studioUploadedBy">anonymous</meta>
<meta id="studioUploaded">1764344209285</meta>
<meta id="studioModifiedBy">anonymous</meta>
<meta id="studioModified">1764344260362</meta>
</metadata>
<contqueries>
<contquery name="cq" trace="Source CreateMulti">
<windows>
<window-source insert-only="true" index="pi_EMPTY" name="Source">
<description><![CDATA[This window receives the input CSV file.]]></description>
<schema>
<fields>
<field name="id" type="string" key="true"/>
<field name="sensorinfo" type="string"/>
</fields>
</schema>
<connectors>
<connector class="fs" name="lua_parse_input">
<properties>
<property name="type"><![CDATA[pub]]></property>
<property name="fsname"><![CDATA[@ESP_PROJECT_HOME@/test_files/luaParseJsonSimple.csv]]></property>
<property name="fstype"><![CDATA[csv]]></property>
</properties>
</connector>
</connectors>
</window-source>
<window-lua events="create" index="pi_EMPTY" name="CreateMulti">
<description><![CDATA[This window uses Lua code to parse the JSON data and generate multiple events.]]></description>
<schema>
<fields>
<field name="id" type="string" key="true"/>
<field name="device_id" type="string"/>
<field name="sensor_id" type="string"/>
<field name="value" type="double"/>
</fields>
</schema>
<copy/>
<code><![CDATA[local eventId = 1
function create(data,context)
local events = {}
local sensorinfo = esp_parseJsonFrom("sensorinfo")
for index,value in ipairs(sensorinfo)
do
local e = {}
e.id = tostring(eventId)
e.device_id = value.device_id
e.sensor_id = value.sensor_id
e.value = value.value
events[index] = e
eventId = eventId + 1
end
return(events)
end]]></code>
</window-lua>
</windows>
<edges>
<edge source="Source" target="CreateMulti"/>
</edges>
</contquery>
</contqueries>
</project>