wifishield esp 8266

Please feedback the issue encountered while using Cytron official website (http://www.cytron.com.my), Cytron Technical Forum and Cytron Tutorial site (http://tutorial.cytron.com.my) here. We greatly appreciate any comments and suggestions too.

wifishield esp 8266

Postby hanmegs » Mon May 23, 2016 3:22 pm

just want to ask on my cytron wifi shield, there is no error on my code, but somehow it got stuck on the middle of the process..the compiling and uploading process are successful. once i open my serial monitor, it can connect through the wifi network but then the shield are not blinking..the blue color led and tx led is stop blinking. when i try using the example, it work correctly. may some some help me..
tq in advance.
hanmegs
Greenhorn
 
Posts: 3
Joined: Mon May 23, 2016 3:15 pm

Re: wifishield esp 8266

Postby bengchet » Mon May 23, 2016 4:43 pm

Hi,

May I know what is the process that stuck in the middle? Can you specify the problem in details? What is the example you are using? If you can show the results in Serial monitor in screenshots it will be better for us to troubleshoot the problem.

Thanks.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: wifishield esp 8266

Postby hanmegs » Tue May 24, 2016 12:55 am

hi bengchet,

tq for the reply. im using Cytron wifi shield esp 8266. it suppose to connect to the network and show the result. how ever, when it manage to connected through the network, the tx and rx led is stop from blinking and the blue color on the esp also stop blinking. when i opened the ip address on the browse, it say that my arduino not send any data..here i attached with the image..


here is the code that i used. it not fully edited yet.. tq for ur help..


#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>

#include "SevSeg.h"
#include <CytronWiFiShield.h>
#include <CytronWiFiServer.h>
#include <SoftwareSerial.h>
#define WiFi wifi


SevSeg sevseg; //Initiate a seven segment controller object
//time counter
int ms =0;
int s =55;
int m =59;
int h =3;
// power calculation
double power1 = 40;
double power2 = 18;
double power3 = 7;
double TIME = 0;
double wattE1;
double wattE2;
double wattE3;
int palceholder;
int deciminalpt;
int currentdisp;
int previousdisp;

//light pin
const int lightswitch1 = A1;
const int lightswitch2 = A2;
const int lightswitch3 = A3;
const int selector = A5;
int dispselect;
bool status = false;
int keyIndex = 1; // your network key Index number (needed only for WEP)
char ssid[] = "Jajajorjes"; // your network SSID (name)
char pass[] = "910906abcd123"; // your network password


ESP8266Server server(80);
void setup()
{


Serial.begin(115200); // initialize serial communication
pinMode(13, OUTPUT);
// check for the presence of the shield:
if (!WiFi.begin(2, 3)) {
Serial.println("WiFi shield not present");
while (true); // don't continue
}

String fv = WiFi.firmwareVersion();
Serial.println(fv);

// attempt to connect to Wifi network:
while (!status) {

Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid); // print the network name (SSID);

status = WiFi.connectAP(ssid, pass); // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
}

server.begin(); // start the web server on port 80
printWifiStatus();


//Setup all the Arduino Pins
pinMode(lightswitch1, OUTPUT);
pinMode(lightswitch2, OUTPUT);
pinMode(lightswitch3, OUTPUT);
pinMode(selector, INPUT);

byte numDigits = 4;
byte digitPins[] = {9,10,11,12};
byte segmentPins[] = {2,3,4,5,6,7,8,13};
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(90);
dispselect = 0;
if (analogRead(selector)> 1000)
{
previousdisp = 1000;

}

else{
previousdisp = 0;
}
//Serial.begin(9600);
}

void loop() {


ESP8266Client client = server.available(); // listen for incoming clients

if(!client) return;
Serial.println("new client");

if (client.connected()) //if client is present and connected
{
String s = client.readStringUntil('\r'); //get the first line of request
// Check to see if the client request was "GET /H" or "GET /L":
if (strstr(s.c_str(),"GET /H"))
Serial.println(wattE1); // GET /H turns the LED on

else if (strstr(s.c_str(),"GET /L"))
Serial.print(wattE2); // GET /L turns the LED off

Serial.print(s);
while(client.available())
Serial.write(client.read()); // print the client request out the serial monitor

// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();

// the content of the HTTP response follows the header:
client.print("Click <a href=\"/H\">here</a> turn the LED on pin 13 on<br>");
client.print("Click <a href=\"/L\">here</a> turn the LED on pin 13 off<br>");

// The HTTP response ends with another blank line:
client.println();
// close the connection:
client.stop();
Serial.println("client disonnected");
}


// Turn OFF any power to the Relay channels
digitalWrite(lightswitch1,LOW);
delay(100);
digitalWrite(lightswitch2,LOW);
delay(100);
digitalWrite(lightswitch3,LOW);
delay(100);
do{
if (analogRead(selector)> 1000)
{
currentdisp = 1000;
}

else{
currentdisp = 0;
}

if (currentdisp != previousdisp)
{
previousdisp = currentdisp;
dispselect = dispselect + 1;
if (dispselect == 3)
{
dispselect = 0;
}
else{

}
}
else{

}

ms = ms+1;
if (ms ==1000)
{
s = s+1;
ms=0;
if (s == 60)
{
m = m+1;
s=0;
if(m == 60)
{
h = h + 1;
m=0;
}
}
}
TIME = (double)(m/60);
TIME = (double)(TIME + h);
wattE1 =(power1 * TIME)/1000;
wattE2 =(power2 * TIME)/1000;
wattE3 =(power3 * TIME)/1000;
/*Serial.print(wattE1);
Serial.print(" KW");
Serial.print('\t');
Serial.print(wattE2);
Serial.print(" KW");
Serial.print('\t');
Serial.print(wattE3);
Serial.println(" KW");*/

if (dispselect == 0)
{
digitalWrite(lightswitch1,HIGH);
digitalWrite(lightswitch2,LOW);
digitalWrite(lightswitch3,LOW);
if (wattE1 >=1000)
{
deciminalpt = 0;
wattE1= wattE1;
palceholder = wattE1;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
else if (wattE1 >=100)
{
deciminalpt = 1;
wattE1= wattE1*10;
palceholder = wattE1;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
else if (wattE1 >=10)
{
deciminalpt = 2;
wattE1= wattE1*100;
palceholder = wattE1;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
else
{
deciminalpt = 3;
wattE1= wattE1*1000;
palceholder = wattE1;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}

delay(1);
}

else if (dispselect == 1){
digitalWrite(lightswitch1,LOW);
digitalWrite(lightswitch2,HIGH);
digitalWrite(lightswitch3,LOW);

if (wattE2 >=1000)
{
deciminalpt = 0;
wattE2= wattE2;
palceholder = wattE2;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
else if (wattE2 >=100)
{
deciminalpt = 1;
wattE2= wattE2*10;
palceholder = wattE2;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
else if (wattE2 >=10)
{
deciminalpt = 2;
wattE2= wattE2*100;
palceholder = wattE2;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
else
{
deciminalpt = 3;
wattE2= wattE2*1000;
palceholder = wattE2;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
delay(10);
}

else if (dispselect == 2){
digitalWrite(lightswitch1,LOW);
digitalWrite(lightswitch2,LOW);
digitalWrite(lightswitch3,HIGH);

if (wattE3 >=1000)
{
deciminalpt = 0;
wattE3= wattE3;
palceholder = wattE3;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
else if (wattE3 >=100)
{
deciminalpt = 1;
wattE3= wattE3*10;
palceholder = wattE3;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
else if (wattE3 >=10)
{
deciminalpt = 2;
wattE3= wattE3*100;
palceholder = wattE3;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
else
{
deciminalpt = 3;
wattE3= wattE3*1000;
palceholder = wattE3;
sevseg.setNumber(palceholder, deciminalpt);
sevseg.refreshDisplay();
}
delay(10);
}
}while(1);
}




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);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
// print where to go in a browser:
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
}
Attachments
2.jpg
as you can see..the RX led is always ON when it able to connect to the network..how ever the TX is not blinking
1.jpg
the view on serial monitor and the web server..
hanmegs
Greenhorn
 
Posts: 3
Joined: Mon May 23, 2016 3:15 pm

Re: wifishield esp 8266

Postby bengchet » Tue May 24, 2016 7:11 am

Hi,

The problem might come from do{...}while(1); The program will keep running in this iteration and will not go back to the first line of void loop(). Function server.available at the first line of void loop() is important for continuous connection between your browser and wifi shield. So you can try reorganise the coding and see if the problem still exists.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: wifishield esp 8266

Postby hanmegs » Tue May 24, 2016 7:55 am

bengchet WROTE:Hi,

The problem might come from do{...}while(1); The program will keep running in this iteration and will not go back to the first line of void loop(). Function server.available at the first line of void loop() is important for continuous connection between your browser and wifi shield. So you can try reorganise the coding and see if the problem still exists.


Hi
Tq for your suggestion. i will try that..
hanmegs
Greenhorn
 
Posts: 3
Joined: Mon May 23, 2016 3:15 pm


Return to Cytron Website, Forum & Tutorial Site Feedback

Who is online

Users browsing this forum: No registered users and 6 guests

cron