London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« on: September 19, 2011, 09:25:09 am » |
Hello all, I am sending a load of sensor readings via UDP to a server but one of the problems I am having is that I cannot send my MAC Address I am trying to figure out a way to convert it to a string so that it can be read by PHP
Thanks xD
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #1 on: September 19, 2011, 09:29:48 am » |
but one of the problems I am having is that I cannot send my MAC Address So, what have you tried? The mac address is an array of bytes. It is nearly trivial to convert the elements in the array to ascii. Separating the elements in the string is the only (trivial) challenge.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #2 on: September 19, 2011, 10:27:58 am » |
packet = {humidity.GetTemperatureC(),humidity.GetHumidity(),epoch,mac[6]};
How is mac defined? Looks to me like you are using the address of the first memory address beyond the location of mac in memory to populate the macaddress array. You can not initialize an array this way.
|
|
|
|
|
Logged
|
|
|
|
|
London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« Reply #3 on: September 19, 2011, 10:54:42 am » |
Sorry but I don't know what I should do, How would I populate the macaddress
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #4 on: September 19, 2011, 11:33:08 am » |
How would I populate the macaddress One element at a time. There are no shortcuts.
|
|
|
|
|
Logged
|
|
|
|
|
London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« Reply #5 on: September 19, 2011, 12:06:16 pm » |
I dont know how I would do that, I really would like some help with this and possibly an example of the code required
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #6 on: September 19, 2011, 12:36:54 pm » |
Since you want to copy an existing array into a new array: for(int i=0; i<6; i++) { packet.macaddress[i] = mac[i]; }
|
|
|
|
|
Logged
|
|
|
|
|
0
Online
Tesla Member
Karma: 51
Posts: 6592
Arduino rocks
|
 |
« Reply #7 on: September 19, 2011, 08:51:17 pm » |
Why don't you store each mac byte as a variable in your code and then use them as needed? You already know what they are when you write the code.
|
|
|
|
|
Logged
|
|
|
|
|
London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« Reply #8 on: September 20, 2011, 12:29:43 pm » |
the reason is that I will be programming over 100 of these devices so by only having to enter the mac address for each device once it will reduce the chance of human error
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #9 on: September 20, 2011, 12:41:47 pm » |
by adding your code i get the following error on the first line Adding it where? Show the code.
|
|
|
|
|
Logged
|
|
|
|
|
London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« Reply #10 on: September 20, 2011, 02:00:33 pm » |
the only place it will let me place the code is within my void setup or loop
I am sorry I really don't understand how to implement the code, I am very new to programming.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #11 on: September 21, 2011, 04:56:26 am » |
What would I have to amend and what would I have to add to get this to send the mac address? You have this code that defines, and (improperly) initializes an instance of, a structure. struct { float temperature; float humidity; unsigned long etime; byte macaddress[6]; } packet = {humidity.GetTemperatureC(),humidity.GetHumidity(),epoch,mac[6]}; I strongly suggest that you separate the definition of the structure from the initialization of the structure. // Define a structure struct contents { float temperature; float humidity; unsigned long etime; byte macaddress[6]; };
// Create an instance of that structure struct contents packet;
// Initialize the instance fields packet.temperature = humidity.GetTemperatureC(); packet.humidity = humidity.GetHumidity(); packet.etime = epoch; for(int i=0; i<6; i++) { packet.macaddress[i] = mac[i]; }
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35593
Seattle, WA USA
|
 |
« Reply #12 on: September 21, 2011, 06:22:59 am » |
would I have to change the formatting of the mac address in there? How are ftemperature, fhumidity, Letime, and Cmacaddress defined? What do you get as the result of the unpack call?
|
|
|
|
|
Logged
|
|
|
|
|
London, UK
Offline
Full Member
Karma: 4
Posts: 179
|
 |
« Reply #13 on: September 22, 2011, 09:24:47 am » |
Don't worry, I figured it out in the end. Thanks anyway
|
|
|
|
|
Logged
|
|
|
|
|
|