Gustavo Gonnet
Published © CC BY-NC-SA

What is my IP?

First impressions of a Raspberry Pi connected to the Particle Cloud.

EasyFull instructions provided1 hour1,900
What is my IP?

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1

Software apps and online services

Particle Cloud
Particle Pi
Particle Pi
porter app

Story

Read more

Code

whatismyip.ino

C/C++
copy-paste this code in your Particle IDE of choice
#include "application.h"

String externalip = "";

void setup() {
  
  // declare cloud variables
  // https://docs.particle.io/reference/firmware/photon/#particle-variable-
  // Up to 20 cloud variables may be registered and each variable name is limited to a maximum of 12 characters.
  Particle.variable("externalip", externalip);
  
  // declare cloud functions
  // https://docs.particle.io/reference/firmware/photon/#particle-function-
  // Up to 15 cloud functions may be registered and each function name is limited to a maximum of 12 characters.
  Particle.function("whatismyip", whatismyip);

}

void loop() {
void loop() {
 // this delay will slow down this rasppi particle agent process so the pi keeps its cool ;)
 // without this delay, top (the command line util on the pi) shows 100% CPU use (of the firmware.bin process)
 // with this delay, top shows 2% CPU use, much better
 delay(1000);
}
}


int whatismyip( String dummyParameter ) {
    
  // source: http://askubuntu.com/questions/95910/command-for-determining-my-public-ip
  Process proc = Process::run("curl ipinfo.io/ip");
  proc.wait();
  
  // The output is the external IP of the rasp PI
  String ipAddress = proc.out().readString();

  // publish it in the console
  Particle.publish("External IP", ipAddress );
  
  //refresh the cloud variable
  externalip = ipAddress;
  
  return 0;
}

Credits

Gustavo Gonnet

Gustavo Gonnet

25 projects • 187 followers
If you need professional help with a project, contact me at gusgonnet@gmail.com
Contact

Comments

Add projectSign up / Login