Decoding payload msg going through lorawan multitech conduit gateway - android

I managed to get a node to communicate to an android app. The message goes from the node to the gateway. Using node-red the gateway publishes the message to an mqtt broker and I subscribe to the right topic to receive that message on my android app.
Only problem I have now is that I never realized that the msg was encoded and I'm quite lost now. I receive an array of bytes on the app side and I'm not sure what is the next step I have to take to be able to read that message.
Thanks for the help!

You are actually receiving bytes from Node-Red. You could either convert the received bytes into String on your Android or modify your lora input node's data type from Bytes to UTF-8.

I have a function to decode it:
var x = Buffer.from(msg.payload.raw,"base64").toString()
msg.Decrypted = parseFloat(x)
return msg;
In this Instructable i explained how to decode Lora messages in node red
https://www.instructables.com/id/Lora-Temperature-Dashboard/

On a MultiTech Conduit, the message is base64 encoded by the internals of the MTC, then published to the internal mqtt broker at lora//up, so you need to base64 decode it, then do whatever you need to with it. You can use the built in mosquitto applications to subscribe to this topic, or any other mqtt client (paho libraries, etc)

Related

Does APNS understand UTF-8 encoded payload

I am using Apns-Node.js for sending push notifications to my iOS device and GCM-Node.js for my Android device.
Currently I have a payload sent to APNS which contains special characters like "ü" in the payload. This gets displayed in the same format and doesn't get truncated or modified by APNS for any reason.
But my Android app has this issue where GCM truncates the special character in the payload unless it is encoded using URL encoding.
"türken" -> gets truncated to "trken" unless it is encoded like "t%C3%BCrken" in GCM only
In an effort to keep both platforms uniform, can I send the encrypted payload to APNS as well? And if I do so, will APNS understand the UTF-8 format and send the payload with special character to the device? My expectation is that APNS should understand the encoded format "t%C3%BCrken" and send "türken" to the device. Will this work?
Based on your explanation, APNS properly supports UTF-8. This means it will deliver the payload as is.
This means if you send "t%C3%BCrken", then the client will receive "t%C3%BCrken", but your iOS client applications can easily remove the percent encoding by using removingPercentEncoding.

Mosquitto publish message format to android app

I am working on a IoT project where i'm using mosquitto broker to get messages to my android app. But when i receive the published messages on my app, they appear to be in a weird format. how can i get the data in correct format. Do i need to change something in mosquitto configuration.
The data sent: "hello"
Received on app: [B#2df51a89
this is what i use to get the text in onMessageReceived(topic,message)
message.getPayload().toString();
Any help is appreciated.
[UPDATE] - When i publish data FROM mobile app, the data is received perfectly at the subscriber. Vice versa doesn't work.
You've printed out the object representation of the byte array (message payload). The correct thing to have done is to create a new String from the byte array using a known encoding (probably UTF8)
String payload = new String(message.getPayload(), "utf8")
Then print the payload String

Android GCM : understanding XMPP

I'm trying to implement a XMPP protocol in my GCM using app, but even after searching extensively, I don't understand the concepts behind it.
Also, maybe I don't really need XMPP for what I want to do with my app, but I like to learn things.
Let's take this example of what I could do with HTTP :
my app send "hello word" and the regId to my little personnal server : url.openConnection(""), then OutputStream for sending POST data and InputStream for getting the response
the server, at this url, put the "hello word" message in a database with the regId, and then use the curl library of php to send data to GCM servers as a json string like {"myResponse":"I'm not world I'm Dan"} (using a test destinator id, in an emulator)
GCM server do his business
my app (maybe on another phone) use an IntentService in a WakefulBroadcastReceiver that get the message as intent.getExtras().getString("myResponse")
This works well and I could send messages from one phone to another using my app, and collecting data on my server the way through.
Very little Question
Is this way of handling HTTP ok theorically ? (I saw a lot of posts and tutorials, especially Google ones, but still not sure)
Big real Question
What are the steps to do the same with XMPP ?
I don't want a tutorial or pieces of codes, I want to understand the way the info goes through this protocol I don't know well (I managed to install ejabberd on my server and use pidgin on my PC and Xabber on my phone).
Official definition:
The Google Cloud Messaging (GCM) Cloud Connection Server (CCS) is an
XMPP endpoint that provides a persistent, asynchronous, bidirectional
connection to Google servers.
Establishing a connection with CCS is the first and most important step here. Once you are done with this and maintain a long-lived connection, other parts are not that tricky.
Some differences between the two:
1) Unlike HTTP, with XMPP messages you do not need to include Authentication headers with every payload since server is authenticated at the time of connecting and we are maintaining the same connection.
2) CCS uses XMPP as a Transport Layer and therefore after you have successfully established connection you can exchange stanzas.
3) You could keep using HTTP for downstream though and use XMPP only for upstream if you wish.
4) Instead of registration_ids param use to: in XMPP and we can only send to one RegID through one stanza.
So if I were to explain how your example would work with XMPP:
- Establish a connection with CCS
- Send an upstream message to your server from the client "Hello, World!"
- Acknowledge once your server receives this message by sending ACK to GCM
- For downstream message you have choice of using either of HTTP or XMPP
- But if XMPP: receive, save in database and when sending response ({"myResponse":"I'm not world I'm Dan"}) back to the client (same or different RegID) send a downstream stanza to CCS; CCS will send ACK/NACK to acknowledge that it has received the message
- You will also receive delivery_receipt (if requested) once the client app has received the message.
Other than this, you can understand more in depth by reading the official documentation which I have linked throughout the post.
Hope this helps!

How to push XML file from server to android application via GCM server

I am trying GCM based android app to push messages from server to android client. I am able to push fix string with the following coe. I am wondering about the ways to push XML file from server and parse at the android application. I have done some research but I couldn't find push XML rather I found send XML file. Thank you
if (androidArray.size() == 1) {
String registrationId = androidArray.get(0);
Message message = new Message.Builder()
.collapseKey(collapseKey)
.timeToLive(30)
.delayWhileIdle(true)
.addData("message", Message)
.build();
Result result = sender.send(message, registrationId, 5);
You don't push xml (or JSON preferably) to the android app. You send a simple message to the app.
when the app receives the message it then needs to go and pull the xml/json from the website with an http get request to the relevant url that will supply the xml.
The android app can then parse the response and do whatever you want it to.
Here is an EXCELLENT tutorial on C2DM (The forerunner to GCM) http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html
You should be able to work out the differences needed.
UPDATE
Google Android has a complete section on GCM which can be found here
http://developer.android.com/google/gcm/index.html
Within that link there are getting started guides and a GCM Demo app
There are limits to the amount of data you can send and you should not rely on your data not ever exceeding the limits or Google arbitrarily changing the amount of data you are allowed to send.
Should either of those occur you would need to update your app so just do it right in the first place.
The message you send should act as a "key" to determine what action to take when the message is received.
UPDATE
If you are feeling REALLY adventurous you could use a custom sync adapter to help you consume your web services. It's pretty advanced stuff but if you are feeling curious about this then watch the Google I/O seminar on consuming RESTfull web services http://www.youtube.com/watch?v=xHXn3Kg2IQE

How to decode space and Chinese character

My server send message through c2dm server
Original msg: This is a string containing 中文 character
But when i receive the message in my android app
Receive: This+is+a+string+containing+%E4%B8%AD%E6%96%87+character
How to decode the message?
Thanks
Construct the response string with UTF-8.Have you tried this?
try this online url decoder
http://meyerweb.com/eric/tools/dencoder/

Categories

Resources