Android Question How to replicate serializator.ConvertObjectToBytes("Message...") functionality for Windows batch files?

amorosik

Expert
Licensed User
I'm trying to send a mqtt message to Mosquitto, a message that should be received by some smartphones
For sending, I use a Windows PC 1 connected via LAN to the Windows PC 2 where Mosquitto is running
For sending from PC 1, I use a batch file that calls the mosquitto_pub.exe program that comes standard with the Mosquitto installation
The line in the batch file looks like this:

mosquitto_pub -h 192.168.2.200 -p 1889 -t topic_name -u username -p password -m "Message to send ..."

The message starts correctly, the broker accepts it and the phones connected and subscribing to the topic topic_name receive it
But now I'm running into the problem that the Payload normally received from the phones is converted from byte to object with the line

Dim receivedObject As Object = serializator.ConvertBytesToObject(Payload)

while in the case of my sending, the Payload is un-converted and when I go to pass it through the above line it breaks all the information
Then I could either avoid converting while receiving, or convert the string to bytes before transmitting
I want to use the second method because the phones already receive from another sender and therefore
I would like to keep that functionality intact

The question is: how to replicate the

serializator.ConvertObjectToBytes("Message to send....")

functionality on a Windows batch file?
 
Last edited:

amorosik

Expert
Licensed User
Yes, without B4Xserializator the message arrives correctly
But the 'receiver', in this case the phones, already have the routine that de-serializes and I wouldn't want to change that procedure because it works fine with other senders made with B4J that use the serializer
I would then like to modify the windows batch file to allow me to keep the currently used standard, with serialization
But I don't know exactly what the ConvertObjectToBytes function does to reproduce it
If I knew how it works I could somehow redo it on the Windows side
 
Upvote 0

teddybear

Well-Known Member
Licensed User
But I don't know exactly what the ConvertObjectToBytes function does to reproduce it
The ConvertObjectToBytes function does what is placing the string into byte array( 1+ string.length + string.getbyte("utf8") )

A simple solution that is you write a mqtt_pub with B4J, and then you can do serializator.ConvertObjectToBytes in it.
You can substitute for the mosquitto_pub with your App.
 
Last edited:
Upvote 0

amorosik

Expert
Licensed User
Yes, this is also a possibility
But the mosquitto_pub.exe is a 50 Kbyte and it definitely tested and already fully working
making a B4J project with its runtime and various libraries, at least a few tens of Mbyte go away, in addition to the fact that it will not be as well-tested as the executable of mosquitto suite
I will probably choose a middle way, send from pc using mosquitto_pub.exe and add a section on the receiver side to allow also reading the payload without serialization
 
Upvote 0

teddybear

Well-Known Member
Licensed User
What is the message you would like to publish? if it is constant ,you can serialize it as a file and publish it using -f option. as well as you can write a C code to generate the file if it is varaiable.
You can also adapt mosquitto client to add a branch option serializing the message.
 
Upvote 0

amorosik

Expert
Licensed User
The message is variable, and is present in an Excel sheet
And therefore I have the vba environment that I can use to create a function similar to the one available in the B4X environments to obtain the same result
If I could get a function that produces the same result as serializator.ConvertBytesToObject("Message") then I could avoid modifying the 'receiving' part
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…