Gustavo
Published © CC BY-NC-SA

What is my IP?

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

BeginnerFull instructions provided1 hour2,689
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
porter app
Particle Pi
Particle Pi

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

Gustavo

33 projects • 301 followers
I focus on creating Particle IoT solutions coupled with mobile and web applications. Available for contract work at gusgonnet@gmail.com.

Comments