Skip to content

Instantly share code, notes, and snippets.

@pfeerick
Last active November 12, 2016 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfeerick/ffbc90d42e3d2477b87ca67d9674aeb4 to your computer and use it in GitHub Desktop.
Save pfeerick/ffbc90d42e3d2477b87ca67d9674aeb4 to your computer and use it in GitHub Desktop.
Simple demo to show how to get a Digistump Oak to change to a Static IP. Isn't the best method, but it works.
//SEMI_AUTOMATIC mode to ensure variable is available
//Probably isn't needed if you don't use Particle.variable in your code
SYSTEM_MODE(SEMI_AUTOMATIC);
#include <ESP8266WiFi.h>
char myIpString[24];
IPAddress myIp;
void setup()
{
// initialize the digital pin as an output.
pinMode(1, OUTPUT); //LED on Oak
//variable visible if using CLI tool or OakTerm
Particle.variable("ipAddress", myIpString);
//since in semi-automatic mode, need to manually connect to particle
Particle.connect();
//publish a message so we know the sketch is running
Particle.publish("oak/userrom/msg", "I'm alive!", PRIVATE);
//IP stuff
IPAddress ip(192, 168, 0, 12);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
//configure the WiFi to use the 'new' settings
WiFi.config(ip, gateway, subnet);
}
// the loop routine runs over and over again forever:
void loop()
{
//obtain current IP address and store in variable
myIp = WiFi.localIP();
sprintf(myIpString, "%d.%d.%d.%d", myIp[0], myIp[1], myIp[2], myIp[3]);
//if you don't want to use the variable, you can publish the IP string instead
//Particle.publish("oak/userrom/currentIP", myIpString, PRIVATE);
//make the P1 led blink for something to do...
for (int i = 0; i < 10; i++)
{
digitalWrite(1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for half a second
digitalWrite(1, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for half a second
}
}
@pfeerick
Copy link
Author

r2 was mainly the addition of more comments, and correcting one or two mistaken comments that hadn't been changed from the initial blink code example sketch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment