I would like to send data via usb, ethernet or bluetooth to my Arduino. Whats the best way to format this? Obviously, XML is two overweight. I did find JSON libs, but I am not sure if this is the best way. Any suggestions?
I am not sure if this is the best way. Any suggestions?
What kind of data? How much? From where? For what purpose? How much control do you have? There is no general purpose answer.
Whats the best way to format this?
It depends on the data that needs to be sent. As you haven't given any clues to that, it's hard to say. It could be as simple as data, or it could be a lot more complex.
(Beaten to it again)
Say, for example, a modulation frequency, a set of pulse and space durations and stuff for an IR signal.
In JSON
{
"Frequency": 38000,
"DelayTimes": [ 500, 1500, 500, 500, 500],
"Gap": 90000
}
Say, for example, a modulation frequency, a set of pulse and space durations and stuff for an IR signal.
In JSON
{
"Frequency": 38000,
"DelayTimes": [ 500, 1500, 500, 500, 500],
"Gap": 90000
}
Is there any reason this data needs to be read as a packet? It looks to me like the frequency, delay times, and gap are separate pieces of information.
They are separate pieces of information needed for the same task: Sending a command.
This is for a project in which an Arduino will act as a converter Ethernet/Wifi/Bluetooth(best would be Wifi, but the common shields and modules are too expensive, so currently I am waiting for a cheap Hongkong BT module)-to-IR (and perhaps later 2.4GHz RF, but currently, there is no device in my household, so I didn't waste any time on that).
In combination with an Android App, this should build a universal remote.
The best solution seem to me to keep the logic inside the AVR as basic as possible, do the work (translation from LIRC files to pulse length etc.) on the Android side and send more or less raw physical information like modulation frequency and pulse-spaces-lengths. This makes it easier to add new functionality without reflashing the device. As one Arduino may control different IR devices, all the information has to be send for every command. I would call that "packet".
Do you need to support any variation in that message structure? For example will the number of delay times always equal five? What range of values will each of those fields need to hold? Is this message the only one you are ever going to need, or do you anticipate needing to add different messages in future?
I would call that "packet".
I would still call it three packets that are all needed to perform an action. You can write code to determine which packet type it is ( would be a frequency packet; <D500, 1500, 500, 500, 500> would be a delay packet; would be a gap packet), parse that packet, and then determine whether anything needed to be done.
For instance, receiving a frequency packet would cause a state change to receiving. Receiving a gap packet would cause a state change to transmitting.
Then, based on the state, there are things to do. Wait for more data (the delay and gap packets), send an IR signal, etc.
@PeterH
I would expect that the structure may change. At least, the DelayTimes length is definatly not constant, as different types of remotes use differend codes.
@PaulS
Ok, I could do that. At least, this would be easy to parse.