ESP8266 WiFi Shield and Arduino Uno Using Telnet

Bluetooth, XBee, RF......

ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby Crystal » Mon Dec 12, 2016 10:22 am

Hi,

I need to communicate with my Arduino Uno using telnet where i can send a char to it via telnet. I have modified the WiFi Chat Server code from Arduino.cc (https://www.arduino.cc/en/Tutorial/WiFiChatServer) to be suited to be used with Cytron ESP8266 WiFi Shield. However, i am facing a problem while compiling my code. Can you please help? Below is my modified code:
CODE: SELECT_ALL_CODE
#include <Keyboard.h>
#include <CytronWiFiShield.h>
#include <CytronWiFiServer.h>
#include <SoftwareSerial.h>
#define WiFi wifi
#include <SPI.h>
#include <string.h>
#include <stdio.h>
#ifdef __AVR__
#endif

char ssid[] = "TDE Office"; //  your network SSID (name)
char pass[] = "tde257a698n";
int keyIndex = 0;            // your network key Index number (needed only for WEP)
ESP8266Server server(23);
boolean alreadyConnected = false; // whether or not the client was connected previously
boolean status = false;

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

  // 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
}


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");
      client.println("Hello, client!");
      alreadyConnected = true;
    }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();
      // echo the bytes back to the client:
      server.write(thisChar);
      // echo the bytes to the server as well:
      Serial.write(thisChar);
      alreadyConnected = false;
      client.println("bye");
      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);

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



and here is my error message:
CODE: SELECT_ALL_CODE
Arduino: 1.6.12 (Windows 7), Board: "Arduino/Genuino Uno"

In file included from C:\Users\AppData\Local\Temp\untitled1835968125.tmp\sketch_dec12a\sketch_dec12a.ino:1:0:

C:\Program Files\Arduino\libraries\Keyboard\src/Keyboard.h:29:2: warning: #warning "Using legacy HID core (non pluggable)" [-Wcpp]

 #warning "Using legacy HID core (non pluggable)"

  ^

In file included from C:\Users\AppData\Local\Temp\untitled1835968125.tmp\sketch_dec12a\sketch_dec12a.ino:2:0:

C:\Users\Documents\Arduino\libraries\CytronWiFiShield-master\src/CytronWiFiShield.h:71:1: warning: 'typedef' was ignored in this declaration

 };

 ^

In file included from C:\Users\Documents\Arduino\libraries\CytronWiFiShield-master\src/CytronWiFiServer.h:26:0,

                 from C:\Users\AppData\Local\Temp\untitled1835968125.tmp\sketch_dec12a\sketch_dec12a.ino:3:

C:\Users\Documents\Arduino\libraries\CytronWiFiShield-master\src/CytronWiFiClient.h: In instantiation of 'size_t ESP8266Client::write(T&) [with T = char; size_t = unsigned int]':

C:\Users\Documents\Arduino\libraries\CytronWiFiShield-master\src/CytronWiFiServer.h:59:34:   required from 'size_t ESP8266Server::write(T&) [with T = char; size_t = unsigned int]'

C:\Users\AppData\Local\Temp\untitled1835968125.tmp\sketch_dec12a\sketch_dec12a.ino:66:28:   required from here

C:\Users\Documents\Arduino\libraries\CytronWiFiShield-master\src/CytronWiFiClient.h:76:25: error: request for member 'available' in 'src', which is of non-class type 'char'

  while (src.available() > 2048)

                         ^

C:\Users\Documents\Arduino\libraries\CytronWiFiShield-master\src/CytronWiFiClient.h:94:13: error: request for member 'read' in 'src', which is of non-class type 'char'

     doneLen += send(src.read());

             ^

C:\Users\Documents\Arduino\libraries\CytronWiFiShield-master\src/CytronWiFiClient.h:102:35: error: request for member 'available' in 'src', which is of non-class type 'char'

  uint16_t leftLen = src.available();

                                   ^

C:\Users\Documents\Arduino\libraries\CytronWiFiShield-master\src/CytronWiFiClient.h:111:12: error: request for member 'read' in 'src', which is of non-class type 'char'

    doneLen += send(src.read());

            ^

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Crystal
Freshie
 
Posts: 7
Joined: Mon Dec 12, 2016 10:09 am

Re: ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby bengchet » Mon Dec 12, 2016 9:24 pm

Hi,

You can try replace server.write(thisChar) with client.print(thisChar).
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby Crystal » Tue Dec 13, 2016 11:34 am

bengchet WROTE:Hi,

You can try replace server.write(thisChar) with client.print(thisChar).


Hi Beng Chet,

Yes it works but another problems come when i try to upload another sketch "CytronWiFiDemo" onto the Arduino. Serial monitor shows error talking to shield and i am not sure what's the problem actually as previously it's working fine. Could you please advise? Thanks.
Crystal
Freshie
 
Posts: 7
Joined: Mon Dec 12, 2016 10:09 am

Re: ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby bengchet » Tue Dec 13, 2016 2:09 pm

Hi,

You can try couple of ways to verify the problem:

1) Is the problem still exists if you try running other example sketches?
2) Are the 2 jumpers on wifi shield connected to RX- D2 and TX - D3?
3) Make sure no other connections share the same pins as D2 and D3.
4) Try press the small button named ESP_RESET beside ESP8266 module on WiFi Shield then restart Arduino board.
5) Try other configurations, like using RX - 8 and TX - 9, setting jumpers on wifi shield according to this and modify the line below
CODE: SELECT_ALL_CODE
wifi.begin(2, 3)
to
CODE: SELECT_ALL_CODE
wifi.begin(8, 9)
and run the sketch. You can use the same method for RX - 10 and TX - 11 etc.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby Crystal » Tue Dec 13, 2016 3:40 pm

bengchet WROTE:Hi,

You can try couple of ways to verify the problem:

1) Is the problem still exists if you try running other example sketches?
2) Are the 2 jumpers on wifi shield connected to RX- D2 and TX - D3?
3) Make sure no other connections share the same pins as D2 and D3.
4) Try press the small button named ESP_RESET beside ESP8266 module on WiFi Shield then restart Arduino board.
5) Try other configurations, like using RX - 8 and TX - 9, setting jumpers on wifi shield according to this and modify the line below
CODE: SELECT_ALL_CODE
wifi.begin(2, 3)
to
CODE: SELECT_ALL_CODE
wifi.begin(8, 9)
and run the sketch. You can use the same method for RX - 10 and TX - 11 etc.


Hi Beng Chet,

I tried upload the example sketch SimpleWebServerWiFi and tried the other configurations of RX8-TX9 and RX10-TX11 but what i get is "WiFi Shield not present". (I did modify the wifi begin as well)
Crystal
Freshie
 
Posts: 7
Joined: Mon Dec 12, 2016 10:09 am

Re: ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby bengchet » Tue Dec 13, 2016 4:34 pm

Hi,

For this case, let's check if the firmware of WiFi module is corrupted.

Steps:
1) Unplug shield from Arduino Uno, put jumpers at USB -RX and USB -TX on the wifi shield.
2) Upload an empty sketch to Arduino Uno.
3) Make sure the small toggle switch is toggled at label 'RUN'. (If it is at FLASH in the beginning, then turn it to 'RUN' and repeat the steps in previous posts)
4) Stack your WiFi shield back to Arduino Uno.
5) Connect Arduino Uno to PC, open serial monitor.
6) Change baud to 9600 and BOTH NL & CR.
7) Type "AT" in text box and click send. If the reply is "OK", the firmware is okay. You can try with other AT command like "AT+GMR".

See how's the result going.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby Crystal » Wed Dec 14, 2016 5:17 pm

bengchet WROTE:Hi,

For this case, let's check if the firmware of WiFi module is corrupted.

Steps:
1) Unplug shield from Arduino Uno, put jumpers at USB -RX and USB -TX on the wifi shield.
2) Upload an empty sketch to Arduino Uno.
3) Make sure the small toggle switch is toggled at label 'RUN'. (If it is at FLASH in the beginning, then turn it to 'RUN' and repeat the steps in previous posts)
4) Stack your WiFi shield back to Arduino Uno.
5) Connect Arduino Uno to PC, open serial monitor.
6) Change baud to 9600 and BOTH NL & CR.
7) Type "AT" in text box and click send. If the reply is "OK", the firmware is okay. You can try with other AT command like "AT+GMR".

See how's the result going.



Hi Beng Chet,

Yes it works. But after some time, here the same problem come. I redo the instructions above once again but this time it give me a blank at serial monitor. What making this device so unstable? Please advise.

*P/s: I am using revision 1 but not 2.
Crystal
Freshie
 
Posts: 7
Joined: Mon Dec 12, 2016 10:09 am

Re: ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby bengchet » Thu Dec 15, 2016 9:02 am

Hi,

Can you show some pictures on your hardware setup, including photos of Arduino Uno, WiFi Shield, and also some screenshots of serial monitor when you are running sketch, and when you run AT command?
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby Crystal » Thu Dec 15, 2016 12:13 pm

bengchet WROTE:Hi,

Can you show some pictures on your hardware setup, including photos of Arduino Uno, WiFi Shield, and also some screenshots of serial monitor when you are running sketch, and when you run AT command?


Hi Beng Chet,

Please refer my hardware setup as follow:
[img]
hardware set up.JPG

[/img]

Please refer to the output when i run AT command:
[img]
AT Test.JPG

[/img]

Please refer to the output when i press on the ESP reset button:
[img]
ESP reset.JPG

[/img]

Thank you.
Crystal
Freshie
 
Posts: 7
Joined: Mon Dec 12, 2016 10:09 am

Re: ESP8266 WiFi Shield and Arduino Uno Using Telnet

Postby bengchet » Thu Dec 15, 2016 12:17 pm

Hi,

Ok you can try a few things here:

1) Change baudrate to 748800 and press ESP-RESET button and see the output.
2) When you try to enter AT command, change baud rate to 115200 and see what is the result.
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 0 guests

cron