London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« on: July 28, 2011, 06:45:45 pm » |
Hi
|
|
|
|
« Last Edit: October 23, 2011, 12:47:35 pm by mrjonny2 »
|
Logged
|
|
|
|
|
0
Online
Tesla Member
Karma: 83
Posts: 8242
:(){:|:&};:
|
 |
« Reply #1 on: July 28, 2011, 09:35:32 pm » |
simply use Udp.sendPacket( packetBuffer, packetBufferSize, address, port); packetBuffer is the array of byte you want sent packetBufferSize is the size of the above packet address is the ip of the destination server port is the port of the destination server
|
|
|
|
|
Logged
|
|
|
|
|
London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« Reply #2 on: July 29, 2011, 08:29:34 am » |
so if I want to send the humidity.GetHumidity() and humidity.GetTemperatureC() as well as sending the current MAC address and the unix time I have just received all in one packet what would the structure of that section be?
Also is it possible to have it work out the packet size itself?
Thanks for the fast reply
|
|
|
|
|
Logged
|
|
|
|
|
0
Online
Tesla Member
Karma: 83
Posts: 8242
:(){:|:&};:
|
 |
« Reply #3 on: July 29, 2011, 09:32:24 am » |
the packets structure is up to you. You write the program on arduino that build the packet and the program on server that read it.
if you want a fixed size structure is easy: GetHumidity and GetTemperatureC, if written as int (and NOT as string) are 2 byte every int, so 4 byte. MAC is a fixed size of 6 byte, unix tiume is a unsigned long(?), so 4 byte. add 2 byte of checksum (to be sure you received correct data), and you have 16 byte of packet.
|
|
|
|
|
Logged
|
|
|
|
|
London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« Reply #4 on: July 29, 2011, 09:59:40 am » |
oh ok so if i were to place GetHumidity within the packet definition would that be a string or int? same for get temp thanks
|
|
|
|
|
Logged
|
|
|
|
|
0
Online
Tesla Member
Karma: 83
Posts: 8242
:(){:|:&};:
|
 |
« Reply #5 on: July 29, 2011, 10:01:39 am » |
if you want it as int, you have to "break" it in byte using bitshif operation (look on the reference or playground to find something about it)
|
|
|
|
|
Logged
|
|
|
|
|
London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« Reply #6 on: July 29, 2011, 05:12:46 pm » |
sorry guys im having some problems working out how to that. im trying to get mac, unixTime, temp, humidity in that order in.
I can't work out how to convert everything into the right formats and get the unix time out
|
|
|
|
|
Logged
|
|
|
|
|
0
Online
Tesla Member
Karma: 83
Posts: 8242
:(){:|:&};:
|
 |
« Reply #7 on: July 29, 2011, 06:41:20 pm » |
first of all you need a byte array of 16 position so:
byte array[16];
then you fill it: int number= 16;//example array[0]=number>>8; //get the fist 8 byte of int array[1]=number; //get the last 8 byte of int (the overflow bit are truncated, same above but with overrun during bitshift)
and so on... mac is already a byte array, just copy it over the new
|
|
|
|
|
Logged
|
|
|
|
|
London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« Reply #8 on: July 29, 2011, 06:49:11 pm » |
the problem i am having is that the get humidty and temperature are all floats
|
|
|
|
|
Logged
|
|
|
|
|
0
Online
Tesla Member
Karma: 83
Posts: 8242
:(){:|:&};:
|
 |
« Reply #9 on: July 29, 2011, 07:39:46 pm » |
float are 4 byte, so: a[0]= float>>(3*8); a[1]= float>>(2*8); a[2]= float>>(1*8); a[3]= float>>(0*8);
that means a[0]= float>>(24); a[1]= float>>(16); a[2]= float>>(8); a[3]= float;
to rebuild it (i think): float=0; for (int i=0; i < 4; i++){ float=float<<8; float = a[i]; }
|
|
|
|
« Last Edit: July 29, 2011, 07:42:31 pm by lesto »
|
Logged
|
|
|
|
|
Wellington, New Zealand
Offline
Sr. Member
Karma: 1
Posts: 404
|
 |
« Reply #10 on: July 30, 2011, 06:54:15 am » |
Maybe try something like: unsigned long sendUDPpacket(byte *address) { struct { float temperature; float humidity; } packet = {humidity.GetTemperatureC(),humidity.GetHumidity()}; Udp.sendPacket( (uint8_t *)&packet, sizeof(packet), tempServer, 6000); // send an UDP packet to the temperature server }
|
|
|
|
|
Logged
|
|
|
|
|
Wellington, New Zealand
Offline
Sr. Member
Karma: 1
Posts: 404
|
 |
« Reply #11 on: July 30, 2011, 05:49:33 pm » |
You would need to add the right data type for the Mac address, e.g byte macadd[6];
|
|
|
|
|
Logged
|
|
|
|
|
|