Pages: [1]   Go Down
Author Topic: Mac Address  (Read 824 times)
0 Members and 1 Guest are viewing this topic.
London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Online Online
Brattain Member
*****
Karma: 610
Posts: 49037
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Online Online
Brattain Member
*****
Karma: 610
Posts: 49037
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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 Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry but I don't know what I should do,  How would I populate the macaddress
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49037
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
How would I populate the macaddress
One element at a time. There are no shortcuts.
Logged

London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Online Online
Brattain Member
*****
Karma: 610
Posts: 49037
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Since you want to copy an existing array into a new array:
Code:
for(int i=0; i<6; i++)
{
  packet.macaddress[i] = mac[i];
}
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9541
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Online Online
Brattain Member
*****
Karma: 610
Posts: 49037
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
by adding your code i get the following error on the first line
Adding it where? Show the code.
Logged

London, UK
Offline Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Online Online
Brattain Member
*****
Karma: 610
Posts: 49037
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Code:
   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.
Code:
// 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
Online Online
Brattain Member
*****
Karma: 610
Posts: 49037
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 Offline
Full Member
***
Karma: 4
Posts: 189
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't worry, I figured it out in the end.  Thanks anyway
Logged

Pages: [1]   Go Up
Jump to: