Hi, I need to learn core’s LocalIp address from the cloud. But I couldn’t get the structure/type of the Network.localIP(). I cant use serial.write because core isnt appeared in device manager list neither as com port or as another thing.
I am afraid that I don’t know much about the Arduino String class but redefining the name localIP from method to variable seems like a bad idea. Here is some code that worked fine for me.
@Dave’s code just expanded on what I wrote to hook up a variable so you can read the IP address of your core from another computer on the internet. This is a good thing.
I had experimented with this earlier and discovered that the cloud API requires HTTPS and so one core cannot (easily) use the API to discover another core. So if you are building say a multisensor network and want the cores to talk to each other, you would need to either (1) use another protocol such as the way cores announce themselves over UDP multicast on powerup or (2) use a full host on your network to act as the “master” to communicate addresses between the cores so they can start talking to each other.
@Dave, maybe that is a longer term feature request: provide a way for a core to query another core variable through the cloud, using the firmware crypto to avoid HTTPS. What do you think?
[EDIT] I see this is very similar to the posting here, so perhaps that is a better way.
We’ve been talking about the best way to accomplish this, and I think we have some really exciting ideas about a feature similar to this. We’re definitely going to build something that will let you do this, and hopefully it will be ready in the next few sprints. First thing I’m building with it is a Core -> Core Telegraph.
You are reading the device, but not the variable. Try adding “/ipAddress” to the end of your URL (before any “?” parameters of course).
The response you got is the one for discovering what functions and variables a core has. This core has one variable named “ipAddress” which is type string and no functions.
This thread was very helpful, but I can’t find where the returned struct (or type) returned by localIP() is defined. Can anyone point me in the right direction?
It is an object called IPAddress which has a lot of methods for printing and setting etc. On Arduino you pass around a 4-byte char array but on Spark that idea is rolled up in the IPAddress object, but you can address it like an array too.
hi
i didn’t understood that how to use.
Which command did i have to type to get out the created spark variable?
I did come from the question to get out the ip address of the Photon?
I have compiled the above code no problem. But i didn’t get together how to get now the ip address.
thx in advance for your help
hape
You can get your IP address cloud variable via many methods, curl, the Particle CLI, a web page, a NodeJS program or any other technology that can do web requests.