General

project with wifi shield v2.2 to tweet

userHead joseda 2015-01-11 22:15:50 6658 Views8 Replies
Hello,
and thanks in advance for your help. I`ve been trying to connect my arduino with the wifi shield to post in a twitter account following the steps here: http://www.instructables.com/id/How-to- ... d/?lang=es (the wifi shield is different from mine). I connect my wifi shield to the router with the instructions of the wifi shield (http://www.dfrobot.com/wiki/index.php/W ... TEL0047%29) but when I compile the program i always get "connection failed". I'm lost and I don't have a clue on what's going on.
These are the steps I follow: 1) connect the wifi shield to the router following the instructions (here I have a doubt if I have to set the TCP server as in the instructions. Do I need to do that?) 2) Upload the program on the Arduino board and I have to change the switch to "Arduino" and "PROG" otherwise i have an error connection uploading the program (in the sketch I have to set the SSID, password and token got from http://arduino-tweet.appspot.com/ to authenticate).  Once I have uploaded the program I open the monitor serial and after 10 seconds I get the connection failed error. Any clue??
2015-01-16 03:12:07 ok, and could you help me with the changes I need to do in the source code to fix the problem?? It seems that the problem is in this sentence: "WiFiClient client;" that uses the library <Wifi.h>. How can I set the networks parameters in this code without using Wifi.h?
Thanks a lot
userHeadPic joseda
2015-01-15 21:36:12 Hello Joseda,

The wifi library is not compatible with this board. their configuration method is different. And it need the remote server IP address which is stored in the Twitter_WiFi library. If you want to use this library, you could check the arduino wifi shield
userHeadPic Grey.CC
2015-01-15 03:41:56 I've been studying the code and playing around with wifi and I have modified the program in this way (removing SSID ,password and token):

#include <Twitter_WiFi.h>
#include <SPI.h> // needed in Arduino 0019 or later
#include <WiFi.h>


char ssid[] = "";  //  your network SSID (name)
char pass[] = "";  // your network password

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("");

// Message to post
char msg[] = "Automatic tweet!";
IPAddress ip(192, 168, 0, 206);
IPAddress dns_server(192, 168, 0, 1);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

void setup()
{
  delay(1000);
  WiFi.begin(ssid, pass);
 
  // or you can use DHCP for automatic IP address configuration.
// WiFi.begin(mac);
  delay(10000);
 
  WiFi.config(ip, dns_server, gateway, subnet);
  Serial.begin(115200);

// print your WiFi shield's IP address:
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());

 
  Serial.println("connecting ...");
  if (twitter.post(msg)) {
    // Specify &Serial to output received response to Serial.
    // If no output is required, you can just omit the argument, e.g.
    // int status = twitter.wait();
    int status = twitter.wait(&Serial);
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }
}

void loop()
{
}

In the program I fix the IP, dns_server, gateway and subnet_mask to the same of my network and to the same I get previously in my dfrobot with AT commands. But no luck I always get "IP Address 0.0.0.0" in the serial monitor. Another thing it's not clear for me is the position of switches: to compile without errors I have to set the switches to "Arduino" and "PROG" but I think once the sketch is compiled and uploaded I have to change the switch from "PROG" to "RUN". Is it correct?? I've tried to run the program in botch cases of the position of the switch but no luck!! Any clue? What am i doing wrong? Thanks in advace
userHeadPic joseda
2015-01-15 03:00:48 Hi again!! I'm racking my brains trying to solve this. I think it's something but i can't see it.

I connect the dfrobot wifi shield to my router following the instructions of here: http://www.dfrobot.com/wiki/index.php/W ... U:TEL0047) (no problem in that: when i do it the leds STW and ASSOC turn on). I set a fixed IP disabling dhcp.

Once my wifi shield is connected to my router I have tried to modify the code of the librarys <Twitter_Wifi.h> and <Twitter_Wifi.cpp>.  The problem is that in <Twitter_Wifi.h> there is a instance of a class defined in <Wifi.h> : WiFiClient client;  I have to use my networks parameter (SSID and password) in the instance "client". 

How do I set the networks parametes in the instance "client"?

Very thanks
userHeadPic joseda
2015-01-14 04:10:34 Thanks a lot for your help Grey.
The code for the library <Twitter_Wifi.h> is very easy but based on <Wifi.h>. In the code there is a definition of a class (class Twitter) that uses the type of WifiClient that I suppose is defined in <Wifi.h>. At the moment I'm totally stuck if you can guide me it will be great!! I don't have to include the <Wifi.h> but then how do I set the parameters to connect to my router? Do I only have to remove the instruction: "WiFi.begin(ssid, pass)" once I have connected my shield to my Wifi network?


The information with the network configuration is not in <Twitter_Wifi> but in the general sketch in:

char ssid[] = "";  //  your network SSID (name)
char pass[] = "";  // your network password

Twitter twitter("");  // Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)


And then with the instruction: WiFi.begin(ssid, pass) is where the configuration of the network is set.

My problem is how do I set the network configuration in the dfrobot wifi shield?? i have done the AT command and I have connected to my Wifi network

*********************************
This is the code of <Twitter_Wifi.h>:
#ifndef TWITTER_H
#define TWITTER_H

#include <inttypes.h>
#include <avr/pgmspace.h>
#if defined(ARDUINO) && ARDUINO > 18  // Arduino 0019 or later
#include <SPI.h>
#endif
#include <WiFi.h>

class Twitter
{
private:
uint8_t parseStatus;
int statusCode;
const char *token;
        WiFiClient client;
public:
Twitter(const char *user_and_passwd);

bool post(const char *msg);
bool checkStatus(Print *debug = NULL);
int  wait(Print *debug = NULL);
int  status(void) { return statusCode; }
};

#endif //TWITTER_H

userHeadPic joseda
2015-01-13 22:01:38 I am afraid no, you know their configuration method is total different. Arduino official wifi shield is using coding to set it parameter. But V2.2 is using AT command. In this point. V2.2 is better for the newbie. easy to use.

There is a library named “<Twitter_WiFi.h>” in the code. It contains the necessary information with the network configuration. for example, the remote server IP address, the remote server port ID. If you could extract these information, and add them to V2.2  It should be work.



userHeadPic Grey.CC
2015-01-13 01:26:58 Thanks Grey for your answer but I'm still stuck.

I think the problem is with #include <Wifi.h>. Could I use the functions of that library with the wifi shield of DFRobot v2.2?. Is my shield able to understand the function Wifi.begin(ssid,pass)?  I can compiled the sketch without errors (with the switches in "Arduino" and "PROG") but when I run the program I get "connection failed".

This is the code I use ( I have deleted my SSID, password and the twitter token)


#include <Twitter_WiFi.h>
#include <SPI.h> // needed in Arduino 0019 or later
#include <WiFi.h>

char ssid[] = "";  //  your network SSID (name)
char pass[] = "";  // your network password

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("");

// Message to post
char msg[] = "Automatic tweet!";

void setup()
{
  delay(1000);
  WiFi.begin(ssid, pass);
  // or you can use DHCP for automatic IP address configuration.
// WiFi.begin(mac);
  delay(10000);
  Serial.begin(115200);

  Serial.println("connecting ...");
  if (twitter.post(msg)) {
    // Specify &Serial to output received response to Serial.
    // If no output is required, you can just omit the argument, e.g.
    // int status = twitter.wait();
    int status = twitter.wait(&Serial);
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }
}

void loop()
{
}
userHeadPic joseda
2015-01-12 10:33:45 Hello Joseda,

This wifi shield is different to the Arduino official one. It is more simple.It doesn't need a coding configuration.
You could set its network parameter with simple AT command. It doesn't need any coding base. It is very convenient for the newbie. You could check its wiki page. Just setting some parameter, it will work.
http://www.dfrobot.com/wiki/index.php/W ... TEL0047%29

I 've checked the instructive tutorial. if you use their library. You need to modify its code. Changing its network parameter. and connecting mode. It is a serial device.
userHeadPic Grey.CC