我有一个模拟器,它像IoT设备一样工作。该设备将十六进制值发送到c8y UI应用程序,在发送十六进制之前,我们需要在c8y UI屏幕上转换ASCII值。
@Name("createdSchema")
create schema UplinkUpdateEvent (
msg Number,
time Date,
msgid string
);
create expression string hexToNum(value)[
function format(hexValue){
var hex = hexValue.toString();
var str = '';
for (var n = 0; n < hex.length; n += 2) {
str += parseInt(hex.substr(n, 2), 16);
}
return str;
};
format(value);
];
@Name("UplinkUpdateEvent")``
insert into UplinkUpdateEvent
select
event.event.source.value as msgid,
event.event.time as time,
hexToNum(getString(event, "objectResourceValue")) as msg
from EventCreated event
where event.event.type.startsWith("c8y_UpLin");
预期结果将为9(十六进制)-> 36(ASCII)