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