Cytron Wifi Shield Rev2.0

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.

Cytron Wifi Shield Rev2.0

Postby Elle » Sun Apr 22, 2018 5:57 pm

Hi, i've bought the Cytron ESP Wi-FI Shield and using it with Arduino Uno Rev 3. I've managed to connect it to the Internet using home wifi but it cant be connected to the net using mobile hotspot. May i know is it possible to connect it to the net using mobile hotspot?
Elle
Freshie
 
Posts: 5
Joined: Fri Mar 16, 2018 5:56 pm

Re: Cytron Wifi Shield Rev2.0

Postby bengchet » Mon Apr 23, 2018 6:57 pm

Hi,

Yes, it is possible. You might need to show your sketch, serial monitor and your phone hotspot settings (SSID, security etc).
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Cytron Wifi Shield Rev2.0

Postby Elle » Wed Apr 25, 2018 9:08 pm

hi, here is the sketch of code used by refering to the example provided named CytronWifiDemo.
CODE: SELECT_ALL_CODE
#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <CytronWiFiServer.h>
#include <SoftwareSerial.h>

const char *ssid = "User's iPhone";
const char *pass = "mobilehotspots";
IPAddress ip(192, 168, 1 ,242);
ESP8266Server server(80);

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() {
 
  // 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(2, 3))
  {
    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
  // Uncomment these 2 lines if you are using static IP Address
  //Serial.println(F("Setup wifi config"));
  //wifi.config(ip);
  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("/"))
    {
      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();
}


and, the result of the serial monitor obtainedis as follow.
Attachments
error connecting to mobile hotspot.PNG
Elle
Freshie
 
Posts: 5
Joined: Fri Mar 16, 2018 5:56 pm

Re: Cytron Wifi Shield Rev2.0

Postby bengchet » Thu Apr 26, 2018 4:03 pm

Hi,

I tested with my android phone by setting same SSID and password, and the shield is working well. Might need to look at your phone hotspot settings. You will need to check SSID, password settings, security settings.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Cytron Wifi Shield Rev2.0

Postby Elle » Mon Apr 30, 2018 4:38 pm

hi, sir! thanks a lot for your advice. I've successfully connected the shield to mobile hotspot that provided by android phone. just that, it's unable to connect to iphone's mobile hotspot. and, i have a question regarding the connection to server using the Cytron ESP Wi-Fi shield. As for now, i still unable to get connected to the desired server using this shield. may i know how to connect the shield with arduino uno to server? and, attached below is the code i tried.
CODE: SELECT_ALL_CODE
#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <CytronWiFiServer.h>
#include <SoftwareSerial.h>
#include <TM1637Display.h>

const char* ssid = "OPPO EK";
const char* pass = "hatake95";
const char* host = "https://qcloud.unimas.my";
const int httpsPort = 3306;

#define CLK 2
#define DIO 3
const int buttonPin = 12; // the number of the pushbutton pin
int state = LOW; // variable for reading the pushbutton status
int lastState = LOW;
int count = 0;
int newcallno;//equal to state

ESP8266Server server(3306);
ESP8266Client client;

TM1637Display display(CLK, DIO);

void setup() {

  pinMode(12, INPUT);
  display.setBrightness(0x0a);
  state = digitalRead(12);
 
  Serial.begin(9600);
 
  if(!wifi.begin(10, 11))
  {
    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
  // Uncomment these 2 lines if you are using static IP Address
  // Serial.println(F("Setup wifi config"));
  // wifi.config(ip);
  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

  ESP8266Client client;
  Serial.print("Connecting to ");
  Serial.println(host);
  if (!client.secure_connect("https://qcloud.unimas.my", 3306))
  {
    Serial.println(F("Failed to connect to server."));
    client.stop();
    return;
  }
  Serial.print(F("Succesfully connected to server"));
}

  void sentData()
  {
  if(client.connect("https://qcloud.unimas.my", 3306))
  {
  String url = "https://qcloud.unimas.my";
  Serial.print("requesting URL: ");
  Serial.println(url);

    client.print(String("PUT"));
    client.print(url);
    client.print("Current Number=");
    client.println(newcallno);
    client.println("HTTP/1.1");//part of the GET request
    client.println("Host:https://qcloud.unimas.my");
    //IMPORTANT: If you are using XAMPP you will have
    //to find out the IP address of your computer and put it here
    //If you have a web page, enter its address(ie.Host: "www.yourwebpage.com")
    client.println("Connection: close");
    //part of the GET request telling the server
    //that we are over transmitting the message
    client.println();
    client.stop();//closing connection to server
  }
  else
  {
    //if arduino can't connect to your server
    Serial.println("Connection failed\n");
  }
 }

void loop()
{
  newcallno = state;
  state = digitalRead(12);
  if (state == HIGH && lastState==LOW)
  {
    count++;
    display.showNumberDec(count);
  }
    lastState = state;
    state = digitalRead(12);
    newcallno=state;
    delay(50);
}


[img]

[/img]
Attachments
failed connection to server (android).PNG
Elle
Freshie
 
Posts: 5
Joined: Fri Mar 16, 2018 5:56 pm

Re: Cytron Wifi Shield Rev2.0

Postby bengchet » Mon Apr 30, 2018 8:25 pm

Hi,

For https connection, please take a look on example HTTPSClient sketch.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Cytron Wifi Shield Rev2.0

Postby Elle » Tue May 01, 2018 3:12 am

hi, sir! i've tried to fix my coding with the httpsclient example but still didn't manage to connect to the server. may i know, what will cause the server connection failure other than the httpsport?

CODE: SELECT_ALL_CODE
#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <SoftwareSerial.h>
#include <TM1637Display.h>

const char* ssid = "carrotgirl";
const char* pass = "kong7000liaw";
const char* host = "qcloud.unimas.my";
const int httpsPort = 443;

#define CLK 2
#define DIO 3
const int buttonPin = 12; // the number of the pushbutton pin
int state = LOW; // variable for reading the pushbutton status
int lastState = LOW;
int count = 0;
int newcallno;//equal to state

TM1637Display display(CLK, DIO);

void setup() {

  pinMode(12, INPUT);
  display.setBrightness(0x0a);
  state = digitalRead(12);
 
  Serial.begin(9600);
 
 if(!wifi.begin(10, 11))
    Serial.println(F("Error talking to shield"));
  Serial.println(F("Start wifi connection"));
 
  if(!wifi.connectAP(ssid, pass))
    Serial.println(F("Error connecting to WiFi"));
  Serial.print(F("Connected to: "));Serial.println(wifi.SSID());
  Serial.print(F("IP address: "));Serial.println(wifi.localIP());

  ESP8266Client client;
  Serial.print("Connecting to ");
  Serial.println(host);
 
  if (!client.secure_connect(host, httpsPort))
  {
    Serial.println(F("Failed to connect to server."));
    client.stop();
    return;
  }
 
  String url = "http://qcloud.unimas.my/api/v1/queues/servicing?service-counter-id=1&new-call-no=0007";
  Serial.print("requesting URL: ");
  Serial.println(url);

  client.print(String("PUT ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");

   Serial.println("request sent");
  //set 5 seconds timeout for response from server
  int i=5000;
  while (client.available()<=0&&i--)
  {
    delay(1);
    if(i==1) {
      Serial.println(F("Timeout"));
      client.stop();
      return;
      }
  }
 
  if(client.available())
  {
    if (client.find("\r\n\r\n"))
      Serial.println(F("headers received"));

    int newcallno = client.read();
    if (digitalRead(12)==HIGH)
      Serial.println(newcallno); 
    else
      Serial.println(F("waiting"));
   
    Serial.println(newcallno);
    Serial.println(F("closing connection"));
   
    //flush the rest of received data
    while(client.available()>0)
      client.flush(); 
  }
 
  client.stop();
}


void loop()
{
  newcallno = state;
  state = digitalRead(12);
  if (state == HIGH && lastState==LOW)
  {
    count++;
    display.showNumberDec(count);
  }
    lastState = state;
    state = digitalRead(12);
    newcallno=state;
    delay(50);
}


and, below is the result obtained.
Attachments
server connection (https).PNG
Elle
Freshie
 
Posts: 5
Joined: Fri Mar 16, 2018 5:56 pm

Re: Cytron Wifi Shield Rev2.0

Postby bengchet » Thu May 03, 2018 2:46 pm

Hi,

Tested with qcloud.unimas.my server, it seems possible to make https connection. It is due to AT firmware itself so we can't do much anything about it.

However, you can try WiFiPushingBoxApi example sketch for your case. Generally it helps to proxy your request so you don't need to connect to your qcloud server directly. However it works with GET and POST. You will need search information or ask qcloud server service provider.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: Cytron Wifi Shield Rev2.0

Postby Elle » Fri May 04, 2018 1:12 am

Hi, thanks a lot for the replies. As for now, I've successfully connected to the server but didn't manage to send data to server. is it due to the AT configuration? and, is there any other way for me to send the data? I think I need to use the httpsclient because the http method that i want to use is PUT as i need to update the sent data from time to time.I've tried to run normal Arduino httpclient coding using the ESP wifi shield, but it seems like cant connect to the WiFi as in the program there's no indication for the TX and RX pin.

CODE: SELECT_ALL_CODE
#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <SoftwareSerial.h>
#include <TM1637Display.h>


const char* ssid = "carrotgirl";
const char* pass = "kong7000liaw";
const char* host = "qcloud.unimas.my";
const int httpsPort = 80;

#define CLK 2
#define DIO 3
const int buttonPin = 12; // the number of the pushbutton pin
int state = LOW; // variable for reading the pushbutton status
int lastState = LOW;
int count = 0;
int newcallno;//equal to state

TM1637Display display(CLK, DIO);

void setup()
{
  pinMode(12, INPUT);
  display.setBrightness(0x0a);
  state = digitalRead(12);
  Serial.begin(9600);

  if(!wifi.begin(10, 11))
    Serial.println(F("Error talking to shield"));
  Serial.println(F("Start wifi connection"));
 
  if(!wifi.connectAP(ssid, pass))
    Serial.println(F("Error connecting to WiFi"));
  Serial.print(F("Connected to: "));Serial.println(wifi.SSID());
  Serial.print(F("IP address: "));Serial.println(wifi.localIP());

  //connect to HTTP server
  Serial.println("\nStarting connection to server...");
  ESP8266Client client;
  Serial.print("Connecting to ");
  Serial.println(host);
   if (!client.connect("qcloud.unimas.my", 80))
   {
    Serial.println(F("Connection failed"));
    return;
   }
   Serial.println(F("Connected to server!"));
}

void loop()
{
  state = digitalRead(12);
  if (state == HIGH && lastState==LOW)
  {
    count++;
    display.showNumberDec(count);
    Serial.println("\nOnline Counter: ");
    Serial.println(count);
    newcallno = state;
   
   //Send HTTP request
  ESP8266Client client;
  client.println(String("PUT ") + "http://qcloud.unimas.my/api/v1/queues/serving?service-counter-id=1&new-call-no=" + newcallno + "HTTP/1.1\r\n" + "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
 
  if (client.println() == 0)
  {
    Serial.println(F("Failed to send request"));
    return;
  }

  // Check HTTP status
  char status[32] = {0};
  client.readBytesUntil('\r', status, sizeof(status));
  if (strcmp(status, "HTTP/1.1 200 OK") != 0)
  {
    Serial.print(F("Unexpected response: "));
    Serial.println(status);
    return;
  }

  // Skip HTTP headers
  char endOfHeaders[] = "\r\n\r\n";
  if (!client.find(endOfHeaders)) {
    Serial.println(F("Invalid response"));
    return;
  }

  //Extract valuees
  Serial.println(F("Current Number: "));
  Serial.println(newcallno);

  //Disconnect
  client.stop();
  }

  lastState = state;
    state = digitalRead(12);
    newcallno=state;
    delay(50);
}
Attachments
serverconnectionsuccess.PNG
Elle
Freshie
 
Posts: 5
Joined: Fri Mar 16, 2018 5:56 pm


Return to Cytron Website, Forum & Tutorial Site Feedback

Who is online

Users browsing this forum: No registered users and 5 guests