Hi,
I am posting code of counter that is writing counts on client.
#include "EEPROM.h"
#include <WiFi.h>
#include <Wire.h>
WiFiServer server(80);
#define MAX_CLIENTS 10
#define EEPROM_SIZE 4
WiFiClient *clients[MAX_CLIENTS] = { NULL };
WiFiClient client;
const char* host = "192.168.98.159";
const int port = 90;
int SIZE;
int num;
char ssid [15];
char password[15];
char temp1 [15];
char temp2 [15];
int addr;
uint8_t ipBuffer[4];
uint8_t gwayBuffer[4];
String inp_cmd = "";
String serialResponse = "";
char x[10];
char y[10];
int i=0;
void setup() {
Serial.begin(115200);
EEPROM.begin(100);
if(EEPROM.read(4) == 255)
{
uint8_t ipBuffer[4] = {10,108,124,5};
uint8_t gwayBuffer[4] ={10,108,124,10};
char ssid[15] = "Smart_Move";
char password[15] = "addverb@123";
addr = 0;
// Write in EEPROM
for (int i = 0; i < 4; i++) {
EEPROM.write(addr, ipBuffer[i]);
addr += 1;}
EEPROM.commit();
addr = 5;
for (int i = 0; i < 12; i++) {
EEPROM.write(addr, ssid[i]);
addr += 1;}
EEPROM.commit();
addr = 20;
for (int i = 0; i < 12; i++) {
EEPROM.write(addr, password[i]);
addr += 1;}
EEPROM.commit();
addr = 35;
for (int i = 0; i < 4; i++) {
EEPROM.write(addr, gwayBuffer[i]);
addr += 1;}
EEPROM.commit();
//IP Details
IPAddress local_IP(ipBuffer[0], ipBuffer[1], ipBuffer[2], ipBuffer[3]);
IPAddress gateway(gwayBuffer[0], gwayBuffer[1],gwayBuffer[2],gwayBuffer[3]);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");}
// Connect to Wi-Fi network with SSID and password
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");}
// Print local IP address and start web server
Serial.println(WiFi.localIP());
server.begin();
uint8_t sta = 111;
EEPROM.write(4,sta);
EEPROM.commit();
Serial.println(EEPROM.read(4));
}
else
{
for (int i = 0; i < 4; i++) {
ipBuffer[i] = EEPROM.read(i);}
for (int i = 0; i < 12; i++) {
ssid[i] = EEPROM.read(i+5);}
for (int i = 0; i < 12; i++) {
password[i] = EEPROM.read(i+20);}
for (int i = 0; i < 4; i++) {
gwayBuffer[i] = EEPROM.read(i+35);}
IPAddress local_IP(ipBuffer[0], ipBuffer[1], ipBuffer[2], ipBuffer[3]);
IPAddress gateway(gwayBuffer[0], gwayBuffer[1],gwayBuffer[2],gwayBuffer[3]);
IPAddress subnet(255, 255, 255, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");}
// Connect to Wi-Fi network with SSID and password
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");}
// Print local IP address and start web server
Serial.println(WiFi.localIP());
server.begin();}
}
void loop() {
// Check if a new client has connected
WiFiClient newClient = server.available();
if (newClient) {
Serial.println("new client");
// Find the first unused space
for (int i=0 ; i<MAX_CLIENTS ; ++i) {
if (NULL == clients[i]) {
clients[0] = new WiFiClient(newClient);
break;
}}}
if(NULL != clients[0] && clients[0]->connected() && clients[0]->available())
{
clients[0]->println(i);
i++;
delay(500);
}
}
Regards
AKANSHA