When I tried to send data to device, I got a handle data-down payload error

Hi~
I always thank you for your project.

When I tried to send data to device, I got a handle data-down payload error in the lora-app-server as below.

INFO[0416] handler/mqtt: data-down payload received topic=application/1/node/0008DCFFFE000001/tx
ERRO[0416] handle data-down payload error: marshal codec payload to binary error: js vm error: TypeError: Cannot access member ‘length’ of undefined application_id=1 dev_eui=0008dcfffe000001 reference=1234

When occurred this situation, I used this data for sending data to device.

  • mosquitto_pub -t ‘application/1/node/0008DCFFFE000001/tx’ -f test_file
  • content of test_file
    {
    “reference”: “1234”,
    “confirmed”: true,
    “fPort”: 10,
    “object”: {
    “temperatureSensor”: {“1”: 25},
    “humiditySensor”: {“1”: 32}
    }
    }

Do you know why print the this error message and how to solved it?

Thank you

@DongEun_Koak_kaizen Hello, I think the problem is that “data” is missing from your JSON sentence. See https://www.loraserver.io/lora-app-server/integrate/data/ for further reference. “data” is the actual value - base64 encoded - you intend to send to the end node.

Hi @glederer007

Thank you for your reply.
Do I must input data? That mean I have to encrypt data of object field and then input enrypted data to data field?

I understood It is not necessary to input data field when I input object field because that recommend.
“when providing the ‘object’, you can omit ‘data’”. Do I have wrong idea?

Thank you ^^

Hello, I don’t know the answer to your question because I didn’t write the program. However I would first try using “data” to see if it works that way. By the way you don’t need to encrypt the data (that is done by the LoRa Server) just encode the data to be base64 encoded…

Hi @glederer007

Could I get a sample data when you tested?
If you can give it to me, It will too helpful ^^

It should be possible without the data payload when you have setup your own JS encoder function. Could you share:

  • LoRa App Server version (or even better, try the latest which is 0.20.1)
  • JS encoder function

Then I can do some testing at my side :slight_smile:

Hi~ @brocaar

I used 0.20.0-1-g45c616f version.
And my encoder is as below. I just want to test for down-link message, I send only 255 unconditionally.

function Encode(fPort, obj) {
//var str1 = obj.myValue;
//var bytes = [];
//for (var i = 0; i < str1.length; i++) {
//var code = str1.charCodeAt(i);
//bytes = bytes.concat([code]);
//}
var bytes = [255,];
return bytes;

}

Thank you^^

I have found an issue in the handling of the returned array. In this case it does not return a []float64 but a []int64 which is not yet handled. I will implement a fix and also implement an error notification so that you can see these errors not only from the logs but also from the web-interface :slight_smile:

I’ve just pushed a fix to the master branch. Could you please test again and let me know if you still have issues? Please note that you will (now) see codec errors under the “live events log” tab on the device page (web-interface). For your convenience you can download pre-compiled snapshots at: https://www.dropbox.com/sh/rago7160i5xzq73/AAC3nxSdDDEg2eUkOtc0xzDPa?dl=0

Looking forward to your feedback!

Hi~ @brocaar

I always thank you for your effort.
Today morning, I tested again using snapshot version of lora-app-server what you shared.

[First Issue]

Unfortunately, I got a these error messages on lora-app-server side.

INFO[0312] handler/mqtt: data-down payload received topic=application/1/node/0008DCFFFE000001/tx
ERRO[0312] handler/mqtt: tx payload unmarshal error: invalid character ‘â’ looking for beginning of object key string data_base64=“ewoJ4oCccmVmZXJlbmNl4oCdOiDigJwxMjM04oCdLAoJ4oCcY29uZmlybWVk4oCdOiB0cnVlLAoJ4oCcZlBvcnTigJ06IDEwLAoJ4oCcb2JqZWN04oCdOiB7CgkJ4oCcdGVtcGVyYXR1cmVTZW5zb3LigJ06IHvigJwx4oCdOiAyNX0sCgkJ4oCcaHVtaWRpdHlTZW5zb3LigJ06IHvigJwx4oCdOiAzMn0KCX0KfQo=”

If you can be possible to share your “Payload encoder function” and data which you sent for down-link using mqtt client, I think you share these data to me. Because I might have used it wrong.

[Second Issue]
When I up-link data using my device, It sent successfully to mqtt-client through lora-server and lora-app-server.
mqtt-client also received data well.

{“applicationID”:“1”,“applicationName”:“wiznet-temp”,“deviceName”:“wiznet-device1”,“devEUI”:“0008dcfffe000001”,“txInfo”:{“frequency”:868300000,“dataRate”:{“modulation”:“LORA”,“bandwidth”:125,“spreadFactor”:7},“adr”:true,“codeRate”:“4/5”},“fCnt”:5,“fPort”:1,“data”:“MTIzNA==”,“object”:{“temperature”:“12”}}

But lora-server printed this error message so I just wonder why print that error message and Do I used it something wrong?

INFO[0320] finished client unary call grpc.code=OK grpc.method=GetDevice grpc.service=ns.NetworkServer grpc.time_ms=4.355 span.kind=client system=grpc
INFO[0320] finished client unary call grpc.code=OK grpc.method=UpdateDevice grpc.service=ns.NetworkServer grpc.time_ms=3.338 span.kind=client system=grpc
INFO[0320] device updated dev_eui=0008dcfffe000001
ERRO[0320] log event for device error error=“gob encode error: gob: type not registered for interface: map[string]interface {}”
INFO[0320] handler/mqtt: publishing message qos=0 topic=application/1/node/0008dcfffe000001/rx
INFO[0320] finished unary call with code OK grpc.code=OK grpc.method=HandleUplinkData grpc.service=as.ApplicationServer grpc.start_time=“2018-04-25T08:46:33+09:00” grpc.time_ms=34.434 peer.address=“127.0.0.1:51468” span.kind=server system=grpc

Thank you. ^^

Hi~ @brocaar

I solved about first issue. My file when used to send MQTT has something wrong character.
I made new file for sending MQTT, It works well and I received data on my device.

My first issue is solved. But could you please give me a sample “Payload encoder function” and answer of my second issue?

Thank you ^^

Could you try again with this snapshot? I’ve also updated the unittest which now reproduces the issue :slight_smile:

Hi,
I have the same problem.

My payload encoder function in App server is:

//  - obj is an object, e.g. {"temperature": 22.5}
// The function must return an array of bytes, e.g. [225, 230, 255, 0]
function Encode(fPort, obj) {
  return [obj.timestamp>>24 && 0xFF,obj.timestamp>>16 && 0xFF,obj.timestamp>>8 && 0xFF,obj.timestamp && 0xFF];
}

Could be this enconder funtion wrong?
You will provide new version with this issue fixed?

Please try the compiled snapshot from the dropbox link and report if this works for you / what error you’re getting :slight_smile:

Should use armv7 for raspberry pi 3?
Thanks

Yes, but there is no harm in trying it out :wink: In the worst case, you will get an error saying that there is an architecture mismatch between your system and the compiled binary.

Thanks @brocaar.
I tried to use compiled snapshot but app crashes after start service.
I get this logs:

May 01 22:29:50 GreenISys lora-app-server[19815]: time="2018-05-01T22:29:50+01:00" level=info msg="connecting to postgresql"
May 01 22:29:50 GreenISys lora-app-server[19815]: time="2018-05-01T22:29:50+01:00" level=info msg="setup redis connection pool"
May 01 22:29:50 GreenISys lora-app-server[19815]: time="2018-05-01T22:29:50+01:00" level=info msg="handler/mqtt: TLS config is empty"
May 01 22:29:50 GreenISys lora-app-server[19815]: time="2018-05-01T22:29:50+01:00" level=info msg="handler/mqtt: connecting to mqtt broker" server="tcp://localhost:1883"
May 01 22:29:50 GreenISys lora-app-server[19815]: time="2018-05-01T22:29:50+01:00" level=info msg="applying database migrations"
May 01 22:29:50 GreenISys lora-app-server[19815]: time="2018-05-01T22:29:50+01:00" level=info msg="handler/mqtt: connected to mqtt broker"
May 01 22:29:50 GreenISys lora-app-server[19815]: time="2018-05-01T22:29:50+01:00" level=info msg="handler/mqtt: subscribing to tx topic" qos=0 topic=application/+/node/+/tx
May 01 22:29:50 GreenISys systemd[1]: lora-app-server.service: Main process exited, code=exited, status=1/FAILURE
May 01 22:29:50 GreenISys systemd[1]: lora-app-server.service: Unit entered failed state.
May 01 22:29:50 GreenISys systemd[1]: lora-app-server.service: Failed with result 'exit-code'.
May 01 22:29:50 GreenISys systemd[1]: lora-app-server.service: Service hold-off time over, scheduling restart.
May 01 22:29:50 GreenISys systemd[1]: Stopped LoRa App Server.
May 01 22:29:50 GreenISys systemd[1]: Started LoRa App Server.
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=warning msg="Deprecation warning! no configuration file found, falling back on environment variables. Update your configuration, see: https://docs.loraserver.io/lora-app-server/install/config/"
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=info msg="starting LoRa App Server" docs="https://docs.loraserver.io/" version=SNAPSHOT-a5e0304
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=info msg="connecting to postgresql"
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=info msg="setup redis connection pool"
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=info msg="handler/mqtt: TLS config is empty"
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=info msg="handler/mqtt: connecting to mqtt broker" server="tcp://localhost:1883"
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=info msg="applying database migrations"
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=info msg="handler/mqtt: connected to mqtt broker"
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=info msg="handler/mqtt: subscribing to tx topic" qos=0 topic=application/+/node/+/tx
May 01 22:29:50 GreenISys lora-app-server[19831]: time="2018-05-01T22:29:50+01:00" level=fatal msg="applying migrations error: pq: operator class \"gin_trgm_ops\" does not exist for access method \"gin\" handling 0027_global_search.sql"
May 01 22:29:50 GreenISys systemd[1]: lora-app-server.service: Main process exited, code=exited, status=1/FAILURE
May 01 22:29:50 GreenISys systemd[1]: lora-app-server.service: Unit entered failed state.
May 01 22:29:50 GreenISys systemd[1]: lora-app-server.service: Failed with result 'exit-code'.
May 01 22:29:51 GreenISys systemd[1]: lora-app-server.service: Service hold-off time over, scheduling restart.
May 01 22:29:51 GreenISys systemd[1]: Stopped LoRa App Server.
May 01 22:29:51 GreenISys systemd[1]: lora-app-server.service: Start request repeated too quickly.
May 01 22:29:51 GreenISys systemd[1]: Failed to start LoRa App Server.
May 01 22:29:51 GreenISys systemd[1]: lora-app-server.service: Unit entered failed state.
May 01 22:29:51 GreenISys systemd[1]: lora-app-server.service: Failed with result 'exit-code'.

Thanks

I see the correction here:
https://www.loraserver.io/lora-app-server/overview/changelog/

But now get other error:
e = Unimplemented desc = unknown method MigrateChannelConfigurationToGatewayProfile"
May 01 22:51:01 GreenISys lora-app-server[20568]: time=“2018-05-01T22:51:01+01:00” level=error msg=“finished client unary call” error=“rpc error: code = Unimplemented desc = unknown method MigrateChannelConfigurationToGatewayProfile” grpc.code=Unimplemented grpc.method=MigrateChannelConfigurationToGatewayProfile grpc.service=ns.NetworkServer grpc.time_ms=1.37 span.kind=client system=grpc
May 01 22:51:01 GreenISys lora-app-server[20568]: time=“2018-05-01T22:51:01+01:00” level=error msg=“gateway-profile migration failed” error=“migrate gateway-profiles for network-server error: migrate channel-configuration to gateway-profile error: rpc error: code = Unimplemented desc = unknown method MigrateChannelConfigurationToGatewayProfile”
May 01 22:51:03 GreenISys lora-app-server[20568]: time=“2018-05-01T22:51:03+01:00” level=error msg=“finished client unary call” error=“rpc error: code = Unimplemented desc = unknown method MigrateChannelConfigurationToGatewayProfile” grpc.code=Unimplemented grpc.method=MigrateChannelConfigurationToGatewayProfile grpc.service=ns.NetworkServer grpc.time_ms=1.834 span.kind=client system=grpc
May 01 22:51:03 GreenISys lora-app-server[20568]: time=“2018-05-01T22:51:03+01:00” level=error msg=“gateway-profile migration failed” error=“migrate gateway-profiles for network-server error: migrate channel-configuration to gateway-profile error: rpc error: code = Unimplemented desc = unknown method MigrateChannelConfigurationToGatewayProfile”
May 01 22:51:05 GreenISys lora-app-server[20568]: time=“2018-05-01T22:51:05+01:00” level=error msg=“finished client unary call” error=“rpc error: code = Unimplemented desc = unknown method MigrateChannelConfigurationToGatewayProfile” grpc.code=Unimplemented grpc.method=MigrateChannelConfigurationToGatewayProfile grpc.service=ns.NetworkServer grpc.time_ms=1.793 span.kind=client system=grpc
May 01 22:51:05 GreenISys lora-app-server[20568]: time=“2018-05-01T22:51:05+01:00” level=error msg=“gateway-profile migration failed” error=“migrate gateway-profiles for network-server error: migrate channel-configuration to gateway-profile error: rpc error: code = Unimplemented desc = unknown method MigrateChannelConfigurationToGatewayProfile”

Are you on the latest LoRa Server version?

Updated to latest version and works. I will test downlink encode function tomorrow.

Thanks @brocaar for your excellent work.