MAC address of ESP-WIFI Shield

Discussion on how to get started with various type of IoT projects

Re: MAC address of ESP-WIFI Shield

Postby amitnagpalmind » Thu May 11, 2017 2:15 pm

Hi Bengchet,

Code is sort of proprietary for our organisation. So, we might not be able to share it at current stage.

We believe that we are getting delay due to "client.println" command.
When we remove this command, there is no delay.

But we need to print something on the display.

Is there any substitute for this command?
amitnagpalmind
Newbie
 
Posts: 12
Joined: Tue Apr 25, 2017 11:41 am

Re: MAC address of ESP-WIFI Shield

Postby bengchet » Thu May 11, 2017 2:35 pm

Hi,

No problem, I can understand that. You can try to combine the content to one line first, before you use client.println to print your content.

Remember, using this shield to perform client.println or client.print frequently is not efficient enough, because these commands consume some delays. So I would suggest using these commands less frequently, with each command to print larger size of content. Therefore, if you use client.println() just only to print 2 characters \r\n, it is not that efficient.

Maximum size for the content for each print is 2046 characters.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: MAC address of ESP-WIFI Shield

Postby amitnagpalmind » Thu May 11, 2017 6:36 pm

Hi Bengchet,

Thanks for the response.

But we have used client.println command only once. Still the reponse is getting delayed by more than the time desired.

Any other command or alternative way for this?
amitnagpalmind
Newbie
 
Posts: 12
Joined: Tue Apr 25, 2017 11:41 am

Re: MAC address of ESP-WIFI Shield

Postby bengchet » Fri May 12, 2017 4:21 pm

Hi,

You can try with this library and see how it goes. Might be the library problem issue.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: MAC address of ESP-WIFI Shield

Postby amitnagpalmind » Fri May 12, 2017 8:10 pm

Below is the demo code and it is not working properly.

We are writing code for blinking of LEDs on the LED strip.

But we are getting variable response each time. Sometimes it works, sometimes it doesn't.

Through code we are assigning RED colour of LED to glow but we find that the White LED glows.




#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <CytronWiFiServer.h>
#include <SoftwareSerial.h>
#include "FastLED.h"
#define NUM_LEDS 10

const char *ssid = "abcd";
const char *pass = "efghijk";
IPAddress ip(172, 29, 42 ,180);
IPAddress gateway(172,29,43,1);
IPAddress subnet(255, 255, 254, 0);

#define DATA_PIN 3
#define CLOCK_PIN 13
ESP8266Server server(80);
CRGB leds[NUM_LEDS];
const char htmlHeader[] = "HTTP/1.1 200 OK\r\n"
"Content-Type: text/html\r\n"
"Connection: close\r\n\r\n"
"<!DOCTYPE HTML>\r\n"
"<html>\r\n";

void setup() {

FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
// put your setup code here, to run once:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

if(!wifi.begin(12, 13))
{
Serial.println(F("Error talking to shield"));
while(1);
}
Serial.println(wifi.firmwareVersion());
Serial.print(F("Mode: "));Serial.println(wifi.getMode());// 1- station mode, 2- softap mode, 3- both
Serial.println(F("Setup wifi config"));
wifi.config(ip,gateway,subnet);
Serial.println(F("Start wifi connection"));
if(!wifi.connectAP(ssid, pass))
{
Serial.println(F("Error connecting to WiFi"));
while(1);
}
Serial.print(F("Connected to "));Serial.println(wifi.SSID());
Serial.println(F("IP address: "));
Serial.println(wifi.localIP());
wifi.updateStatus();
Serial.println(wifi.status()); //2- wifi connected with ip, 3- got connection with servers or clients, 4- disconnect with clients or servers, 5- no wifi
clientTest();
espblink(100);
server.begin();
}

void loop() {
// put your main code here, to run repeatedly:
serverTest();
}

void espblink(int time)
{
for(int i = 0;i<12;i++)
{
wifi.digitalWrite(2,wifi.digitalRead(2)^1);
delay(time);
}
}

void serverTest()
{
ESP8266Client client = server.available();

if(client.available()>0)
{
String req = client.readStringUntil('\r');
// First line of HTTP request looks like "GET /path HTTP/1.1"
// Retrieve the "/path" part by finding the spaces
int addr_start = req.indexOf(' ');
int addr_end = req.indexOf(' ', addr_start + 1);
if (addr_start == -1 || addr_end == -1) {
Serial.print(F("Invalid request: "));
Serial.println(req);
return;
}
req = req.substring(addr_start + 1, addr_end);
Serial.print(F("Request: "));
Serial.println(req);
client.flush();

if(req.equals("/"))
{

for(int i=0;i<10;i++)
{leds[i] = CRGB::Red;
FastLED.show();
//delay(500);
}
// Now turn the LED off, then pause
for(int i=0;i<10;i++)
{
leds[i] = CRGB::Black;
FastLED.show();
delay(500);
}



}
/*{
IPAddress ip = wifi.localIP();
String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
client.print(htmlHeader);
String htmlBody = "Hello from ESP8266 at ";
htmlBody += ipStr;
htmlBody += "</html>\r\n\r\n";
client.print(htmlBody);
}
*/
else if(req.equals("/analog"))
{
client.print(htmlHeader);
String htmlBody="";
for (int a = 0; a < 6; a++)
{
htmlBody += "A";
htmlBody += String(a);
htmlBody += ": ";
htmlBody += String(analogRead(a));
htmlBody += "<br>\r\n";
}
htmlBody += "\r\n</html>\r\n";
client.print(htmlBody);
}

else if(req.equals("/gpio2"))
{
wifi.digitalWrite(2, wifi.digitalRead(2)^1);
client.print(htmlHeader);
String htmlBody="GPIO2 is now ";
htmlBody += wifi.digitalRead(2)==HIGH?"HIGH":"LOW";
htmlBody += "</html>\r\n";
client.print(htmlBody);
}

else if(req.equals("/info"))
{
String toSend = wifi.firmwareVersion();
toSend.replace("\r\n","<br>");
client.print(htmlHeader);
client.print(toSend);
client.print("</html>\r\n");
}

else
client.print("HTTP/1.1 404 Not Found\r\n\r\n");

client.stop();

}
}

void clientTest()
{
const char destServer[] = "www.adafruit.com";
ESP8266Client client;
if (!client.connect(destServer, 80))
{
Serial.println(F("Failed to connect to server."));
client.stop();
return;
}

const char *httpRequest = "GET /testwifi/index.html HTTP/1.1\r\n"
"Host: www.adafruit.com\r\n"
"Connection: close\r\n\r\n";
if(!client.print(httpRequest))
{
Serial.println(F("Sending failed"));
client.stop();
return;;
}

// set timeout approximately 5s for server reply
int i=5000;
while (client.available()<=0&&i--)
{
delay(1);
if(i==1) {
Serial.println(F("Timeout"));
return;
}
}

while (client.available()>0)
{
//char c = (char)client.read();
//Serial.print(c);
Serial.write(client.read());
}

client.stop();
}
amitnagpalmind
Newbie
 
Posts: 12
Joined: Tue Apr 25, 2017 11:41 am

Re: MAC address of ESP-WIFI Shield

Postby bengchet » Fri May 12, 2017 9:44 pm

Hi,

1. Have you tried this code without WiFi? From my experience, there will be no red LEDs shown as expected because there are no delays.
2. Second thing is, using delay(500) is not suitable. The whole program is sequential, not asynchronus, meaning that it will wait until LED finishes showing before sending reply back to client. That is the reason why you will get slow response. From the code, it takes like 500ms x 10 x 2 = 10s to complete (on and off phases). By that time, it has already reached timeout to send reply back to client.

CODE: SELECT_ALL_CODE
for(int i=0;i<10;i++)
{
leds[i] = CRGB::Red;
FastLED.show();
//delay(500); <-- No Delay, the program runs faster than we see
}
// Now turn the LED off, then pause
for(int i=0;i<10;i++)
{
leds[i] = CRGB::Black;
FastLED.show();
delay(500);
}




Please open a new topic for new issue as this is not related to MAC Address issue anymore. Thanks.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: MAC address of ESP-WIFI Shield

Postby amitnagpalmind » Tue May 16, 2017 8:15 pm

Hi Bengchet
We are trying to control the +5V RGB LED strip, (part number WS2812B) by deploying the Cytron ESP8266 Wi-Fi shield over Arduino Mega 2560.

We are giving the voltage source to LEDs externally (SMPS power specs. output: +5V, 40A) and signal source through Arduino GPIO via Cytron Wifi-shield.

But the issue is that when we connect around upto 250 LEDs, it works fine. But when we further increase the number of LEDs, the shield automatically gets disconnected (and power gets switched off, only from shield, and power on Arduino still remains).

What could be the issue?
The Arduino is powered up with DC adaptor (+5V, 2.5A) as well as USB from PC.

This was however not the case with Arduino Ethernet shield, or Arduino Wifi shield.
amitnagpalmind
Newbie
 
Posts: 12
Joined: Tue Apr 25, 2017 11:41 am

Re: MAC address of ESP-WIFI Shield

Postby bengchet » Thu May 18, 2017 10:37 am

Hi,

This is likely hardware issue. If possible provide us some hardware photos regarding the following.

1. The Arduino is powered up with DC adaptor (+5V, 2.5A) as well as USB from PC. Show us the photos how you do this.

2. We are giving the voltage source to LEDs externally (SMPS power specs. output: +5V, 40A) and signal source through Arduino GPIO via Cytron Wifi-shield. Just show us the wire connection between LEDs and Arduino (signal source wire, GND wire, etc)

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

Re: MAC address of ESP-WIFI Shield

Postby amitnagpalmind » Fri May 19, 2017 10:33 pm

Thanks a lot bengchet. All the previous issues solved. Shield is working.

We have another query now. The query is that how can i write the code or firmware over ESP8266 (module on cytron shield) itself, through Arduino IDE, rather than writing the code only on base board like Arduino Uno or Arduino Mega?

We need to have two different codes, one on the Cytron ESP8266 shield and one on the Arduino Mega board.

I need to know the hardware configuration and the programming interface, as I could not find any programming interface on the Cytron Shield.
amitnagpalmind
Newbie
 
Posts: 12
Joined: Tue Apr 25, 2017 11:41 am

Re: MAC address of ESP-WIFI Shield

Postby bengchet » Mon May 22, 2017 10:16 am

Hi,

For programming interface for ESP8266 on Cytron WiFi Shield, you can use UC00A/UC00C or other USB-Serial adapter to do so, or another alternative is use another Arduino-like board such as Arduino Uno, CT-Uno, Mega. Which method you prefer?

Note: Last reminder, please open this issue on new topic, I will consider this topic closed as it is not related to MAC address of ESP-WIFI Shield. You can open topic named with "Programming interface on ESP8266 on Cytron WiFi Shield". We shall continue this discussion on new topic, thanks for cooperation.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Previous

Return to Getting Started - IoT

Who is online

Users browsing this forum: No registered users and 2 guests

cron