CYTRON WIFI SHIELD REV2.0 client problem

Bluetooth, XBee, RF......

CYTRON WIFI SHIELD REV2.0 client problem

Postby nazri94 » Wed Apr 05, 2017 4:25 pm

Hello,

I just bought Cytron Wifi Shield Rev2.0 last week. I used it with Arduino Mega2560. I got no problem connecting to wifi. However, i have a problem to connect the arduino to a server as a client. I just try to run the all the client example, it give respond "Failed to connect to server". I run HTTPSClient example, HTTPSGoogleform example and CytronWifiDemo example and all of it give the same respond.

below is the HTTPS example code.

CODE: SELECT_ALL_CODE
/*
 *  HTTP over TLS (HTTPS) example sketch
 *
 *  This example demonstrates how to use
 *  secure_connect function to access HTTPS API.
 *  We fetch and display the status of
 *  esp8266/Arduino project continuous integration
 *  build.
 *
 *  Created by Ivan Grokhotkov, 2015.
 *  This example is in public domain.
 * 
 *  Modified by Ng Beng Chet, 2016
 */

#include <CytronWiFiShield.h>
#include <CytronWiFiClient.h>
#include <SoftwareSerial.h>

const char* ssid = "Connectify-me";
const char* pass = "syaza1994";

const char* host = "api.github.com";
const int httpsPort = 443;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  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 = "/repos/esp8266/Arduino/commits/master/status";
  Serial.print("requesting URL: ");
  Serial.println(url);

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: BuildFailureDetectorESP8266\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"));

    String line = client.readStringUntil('\n');
    if (line.startsWith("{\"state\":\"success\""))
      Serial.println(F("esp8266/Arduino CI successfull!")); 
    else
      Serial.println(F("esp8266/Arduino CI has failed"));
   
    Serial.println(F("reply was:"));
    Serial.println(F("=========="));
    Serial.println(line);
    Serial.println(F("=========="));
    Serial.println(F("closing connection"));
   
    //flush the rest of received data
    while(client.available()>0)
       client.flush(); 
  }
 
  client.stop();
}

void loop() {
}


The other code is the same as the example in the library. By the way, i also try to run the SimpleWifiWebserver example, it can run smoothly.

Can anyone help me to solve this problem. This is because i want to use client library for my project. Thank you in advance.
Attachments
https example.PNG
HTTPS example response
https example.PNG (8.43 KiB) Viewed 5116 times
googleform example.PNG
Googleform example response
googleform example.PNG (8.17 KiB) Viewed 5116 times
cytronwifidemo.PNG
Cytron Wifi Demo example response
nazri94
Greenhorn
 
Posts: 2
Joined: Wed Apr 05, 2017 4:10 pm

Re: CYTRON WIFI SHIELD REV2.0 client problem

Postby bengchet » Thu Apr 06, 2017 9:44 am

Hi,

Lets try with CytronWiFiDemo sketch first for HTTP connection as client first. We will deal with HTTPS connection later on. In the sketch try to comment/remove the line wifi.config(ip) to allow wifi shield to get random IP address assigned by your network router.
bengchet
Moderator
 
Posts: 237
Joined: Tue Aug 25, 2015 8:29 am

Re: CYTRON WIFI SHIELD REV2.0 client problem

Postby nazri94 » Thu Apr 06, 2017 1:59 pm

Wow! it is working!! Thank you very much! I also try to make a connection to my local server and it is working...this is really helping me... btw, can u tell me why wifi.config is not working in the sketch? and also what is the possible problem for the https example?

Here i attach the response of the sketch
Attachments
connect to local server.PNG
Connection to local server
Working wifi demo.PNG
Wifi demo working
nazri94
Greenhorn
 
Posts: 2
Joined: Wed Apr 05, 2017 4:10 pm

Re: CYTRON WIFI SHIELD REV2.0 client problem

Postby bengchet » Thu Apr 06, 2017 4:20 pm

Hi,

It is because of your network IP address. If you wish to use static IP address, you can use wifi.config(ip). However, you should change IP address ip in form 192.168.165.xxx instead of 192.168.1.xxx. But if you wish not to use static IP address, you can just ignore it.

As for HTTPS connection, it is due to AT firmware is not updated. Do check our user manual 8.0 firmware installation to update the firmware. This firmware adds functionality HTTPS client connection and 3v3 GPIO control.
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 15 guests

cron