How to Change the IP address of Cytron Wifi Shield

Bluetooth, XBee, RF......

How to Change the IP address of Cytron Wifi Shield

Postby Crystal » Wed Jan 25, 2017 2:09 pm

Hi,

Can i know how could i change the wifi shield IP, gateway and subnet?

CODE: SELECT_ALL_CODE
#include <CytronWiFiShield.h>
#include <CytronWiFiServer.h>
#include <SoftwareSerial.h>
#define WiFi wifi
#include <SPI.h>
#include <string.h>
#include <stdio.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

char ssid[] = "XXX"; //  your network SSID (name)
char pass[] = "$1$k2w6$PT6kyiXb/h1dY8sq";
IPAddress ip(10, 204, 191, 40);
IPAddress gateway(10, 204, 188, 1);
IPAddress subnet(255, 255, 252, 0);

ESP8266Server server(80);
int keyIndex = 0;            // your network key Index number (needed only for WEP)
boolean alreadyConnected = false; // whether or not the client was connected previously
boolean status = false;
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN            13
#define PIN2           12
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      4
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2 = Adafruit_NeoPixel(NUMPIXELS, PIN2, NEO_GRB + NEO_KHZ800);
int delayval = 50; // delay for half a second


void setup() {
   Serial.begin(9600);
   while (!Serial) {
    ;
   }
    if (!WiFi.begin(2, 3)) {
    Serial.println("WiFi shield not present");
    while (true);       // don't continue
  }

  String fv = WiFi.firmwareVersion();
  Serial.println(fv);
  wifi.config(ip, gateway, subnet);
  // attempt to connect to Wifi network:
  while (!status) {
   
  Serial.print("Attempting to connect to Network named: ");
  Serial.println(ssid);                   // print the network name (SSID);
   
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  status = WiFi.connectAP(ssid, pass);
  }
  server.begin();                           // start the web server on port 80
  printWifiStatus();                        // you're connected now, so print out the status
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code
  pixels.begin(); // This initializes the NeoPixel library.
  pixels2.begin();
}


void loop() {
  // wait for a new client:
  ESP8266Client client = server.available();

  // when the client sends the first byte, say hello:
  if (client) {
   
//    if (!alreadyConnected) {
//      // clead out the input buffer:
//      client.flush();   
//      Serial.println("We have a new client!");
//      alreadyConnected = true;
//    }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      String incomingBytes = client.readString();
      char charBuf[4];
      incomingBytes.toCharArray(charBuf, NUMPIXELS);
      for (int j=0; j<NUMPIXELS; j++) {
      charBuf[j]=incomingBytes[j];

    for (int j=0; j<4; j++) {
    Serial.print(charBuf[j]);

        if (charBuf[j] == 'R') {
        pixels.setPixelColor(j, pixels.Color(50,0,0));
        }
     
          else if (charBuf[j] == 'G') {
          pixels.setPixelColor(j, pixels.Color(0,50,0));   
          }

          else if (charBuf[j] == 'B') {
          pixels.setPixelColor(j, pixels.Color(0,50,50));   
          }

          else if (charBuf[j] == 'W') {
          pixels.setPixelColor(j, pixels.Color(50,50,0)); 
          }

          else if (charBuf[j] == 'O') {
          pixels.setPixelColor(j, pixels.Color(0,0,0)); 
          }
    }

    for (int j=40; j<NUMPIXELS; j++) {
    Serial.print(charBuf[j]);

        if (charBuf[j] == 'R') {
        pixels2.setPixelColor(j-44, pixels2.Color(10,0,0));
        }
   
          else if (charBuf[j] == 'G') {
          pixels2.setPixelColor(j-44, pixels2.Color(0,10,0));   
          }

          else if (charBuf[j] == 'B') {
          pixels2.setPixelColor(j-44, pixels2.Color(0,0,10));   
          }

          else if (charBuf[j] == 'W') {
          pixels2.setPixelColor(j-44, pixels2.Color(10,10,10)); 
          }

          else if (charBuf[j] == 'O') {
          pixels2.setPixelColor(j-44, pixels2.Color(0,0,0)); 
          }
    }
   
    pixels.show(); // This sends the updated pixel color to the hardware.
    pixels2.show();
    delay(delayval); // Delay for a period of time (in milliseconds).
//    client.flush();
    alreadyConnected = false;
    client.stop();       
   }
  }
 }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  Serial.print("IP Gateway: ");
  Serial.println(gateway);
  Serial.print("IP Subnet: ");
  Serial.println(subnet);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}


I tried whatever method but still get no response from the device. Please advise.
Crystal
Freshie
 
Posts: 7
Joined: Mon Dec 12, 2016 10:09 am

Re: How to Change the IP address of Cytron Wifi Shield

Postby bengchet » Thu Jan 26, 2017 9:00 am

Hi,

Ok first of all, if you can provide us the screenshot of Arduino Serial Monitor showing the logs, it will be better for us to troubleshoot.

I have tested Shield Rev1.0 with wifi.config as mentioned, with ip, gateway and subnet parameters properly configured, I was able to connect to the network. I was using CytronWiFIDemo example, and I was also able to view webpage from accessing the IP address at Google web browser. So my suggestion is try wifi.config with CytronWiFiDemo example first before trying your own program. If the result is good, obviously you will have to look into your coding controlling RGB neopixels.

How to check if CytronWiFIDemo sketch is working:
1) Following message appears on Serial monitor:
CODE: SELECT_ALL_CODE
This is a test of the CC3000 module!
If you can read this, its working :)


2) You can see message Hello from ESP8266... from accessing IP at web browser, assuming ESP is connect to same network as your PC.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am


Return to Wireless Device

Who is online

Users browsing this forum: No registered users and 13 guests