Help! Tweet fails with code "0"

Home Forums Botanicalls Community Help! Tweet fails with code "0"

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1565
    drewc
    Participant

    Hi…After customizing and compiling V 3.01 code and plugging-in a new Twitter OAuth token, things seem to be working (i.e., DHCP OK, IP assigned, etc.), except that I am receiving the following error status from Twitter: “Tweet Fail: Code 0”. Here’s the stream:

    Botanicalls v3.01

    mac: 31:13:31:13:31:13

    token: 601291366-SUUChc6mPLhQR5Eamzfv1zVs3ywtkpzcPtI3b8w8

    serial: 4B2D

    ctr: 48

    DHCP req

    DHCP OK!

    ip: 192.168.1.78

    gw: 192.168.1.254

    dns: 192.168.1.254

    moisture level: 870 average: 870

    connect…

    tweet fail: code 0

    TEST tweet

    connect…

    tweet fail: code 0

    ip: 192.168.1.78

    gw: 192.168.1.254

    dns: 192.168.1.254

    moisture level: 870 average: 869

    The “code 0” return from NeoCat’s proxy site is not particularly useful in debugging…any ideas as to what I am doing wrong? Thanks!

    Drew

    #1862
    Rob Faludi
    Keymaster

    I’m not familiar with that error.

    #1863
    drewc
    Participant

    Hi Rob – I suspect that either the DHCP lease is not providing a proper IP address, or the Neocat proxy is somehow not happy with what it’s receiving from the Botanicalls code. The former seems unlikely as the above stream indicates what looks like a valid IP, gateway, dns, etc. More likely, I think, is something amiss in the way it’s talking to Twitter via the proxy. I have tested with sample DHCP/DNS code and tested my Neocat token as well — both work. So, I’m not sure where to go next…appreciate any ideas. Thanks!

    #1865
    Rob Faludi
    Keymaster

    Well the first question would be what was customized and does the code work pre-customization?

    #1866
    drewc
    Participant

    Rob, here’s is what I am running with:

    – I’m using Botanicalls V3.01 “customize” codebase from here: http://code.google.com/p/botanicalls/downloads/list

    – I have replaced the Twitter token with one I have generated (but also tested with your “@Botanicallstest” token

    – I have also updated some of the associated libraries (e.g., EthernetDHCP, EEProm, TrueRandom) to work with IDE 1.0 (e.g., replaced references to “Wiring.h”, “String.h” and “WProgram.h” with “Arduino.h”)

    – Complies cleanly with Arduino 1.01 (and 1.0 as well)

    – Both Twitter Library and Ethernet Library samples work fine..I am able to set and get DHCP leases and addresses

    – As far as I can tell, the code works ok until I pass to Twitter, where I get the HTTP return status of “0” which the docs tell me means it is not actually getting to Twitter’s server. As I said above, I have tried the @botanicallstest and my own token with no success.

    Thanks for any insights.

    So I’m not sure where things are going wrong…all seems to be working and yet no tweets.

    #1867
    drewc
    Participant

    Good news! The code is now running and tweeting after I modified the way DHCP manages leases. Briefly, I replaced the Ethernet.DHCP syntax with the new (as of Arduino 1.01) Ethernet format, using Ethernet.begin and Ethernet.maintain to start and maintain the DHCP leases. Tried several times and seemed to work well . Thanks again.

    #1868
    squigley
    Participant

    Hi Drew,

    Could I get some details on those changes? I’ve just hit the same issue. Running tcpdump on the interface the kit is attached to show it’s getting a lease, but when I try to do a test tweet, there’s no network activity at all.

    I even tried hard coding the IP of the server in case it was a DNS issue, and then found this thread, so if you could let me know how I modify EthernetDHCP.cpp (or a different file?), to use the other syntax, it would be appreciated :-)

    #1869
    squigley
    Participant

    Wow, this isn’t a very trivial change. I managed to hack a few changes in, to use Ethernet.begin and Ethernet.maintain instead, and got it working, but my changes were pretty dirty :-)

    in the main file under // start Ethernet I added:

    Ethernet.begin(mac); // start ethernet DHCP in non-blocking polling mode
    Serial.println(Ethernet.localIP());
    ipState = DhcpStateLeased;

    in utility I had to make changes in the dhcpCheck function, adding

    int State = Ethernet.maintain(); // poll for an updated state

    and commenting out the check for a state change, and changing the switch to switch State, then adding case ‘2’ under DhcpStateLeased.

    After that it worked, and it should keep it’s lease, but we’ll find out..

    #1870
    Joe
    Participant

    Hi Squigley,

    I’m working on the same problem with DHCP leases on the Botanicalls and have made my own dirty changes to get the code working. I’ve completely commented out the DHCP check subroutine, as I couldn’t get the new ethernet.maintain command working with it.

    Could you tell me more about the changes you made in the above post? and/or post the code? I think my code will have problems as it never renews the DCHP lease.

    Also, I think the the EthernetDHCP, Ethernet DNS libraries are not necessary with the new Ethernet library in Arduino 1.0. Would you agree?

    #1871
    squigley
    Participant

    Hey Joe,

    It would be possible to completely remove the EthernetDHCP and EthernetDNS library requirement, I think, and with the changes I made, I’ve all but removed them.

    Some variables need to be defined that are used, that are expected to be initialised by the inclusion of the above libraries.

    After my above post about the “dirty” changes I made, I made some more changes, reprogrammed the device, and realised I had it checking the DHCP lease constantly.

    I subsequently made some more changes, using millis() to only check the lease every hour, which could probably be increased more.

    I made some large changes to the DHCPcheck function, replacing all the switch/case statements with the return codes from the new version.

    I didn’t really want to post my code, since it’s pretty ugly, but in case there’s someone else with the same issue, I want to give them something to work with, so here goes..

    // start Ethernet
    //EthernetDHCP.begin(mac, true); // start ethernet DHCP in non-blocking polling mode
    if (Ethernet.begin(mac) == 1) { // start ethernet DHCP in non-blocking polling mode
    Serial.println("DHCP discovery success");
    Serial.print("ip: ");
    Serial.println(Ethernet.localIP());
    ipState = DhcpStateLeased;
    }
    else {
    while (Ethernet.begin(mac) == 0){
    Serial.println("DHCP discovery failed");
    delay(5000); // wait 5 seconds
    }
    }

    void loop()       // main loop of the program
    {
    moistureCheck(); // check to see if moisture levels require Twittering out
    wateringCheck(); // check to see if a watering event has occurred to report it
    buttonCheck(); // check to see if the debugging button is pressed
    analogWrite(COMMLED,0); // douse comm light if it was on
    if (millis() % 3600000 == 0){
    // an hour has passed
    delay(2000);
    dhcpCheck(); // check and update DHCP connection
    }
    if (millis() % 60000 == 0 && ipState != DhcpStateLeased && ipState != DhcpStateRenewing) {
    blinkLED(COMMLED,1,30); // quick blnk of COMM led if there's no ip address
    }
    }

    // check and attempt to create a DHCP leased IP address
    void dhcpCheck() {
    //DhcpState prevState = ipState; // record the current state
    //ipState = EthernetDHCP.poll(); // poll for an updated state
    Serial.println("DHCP update..");
    int State = Ethernet.maintain(); // poll for an updated state
    //if (prevState != ipState) { // if this is a new state then report it
    //switch (ipState) {
    switch (State) {
    //case DhcpStateDiscovering:
    //Serial.println("DHCP disc");
    //break;
    //case DhcpStateRequesting:
    //Serial.println("DHCP req");
    //break;
    //case DhcpStateRenewing:
    //Serial.println("DHCP renew");
    //break;
    //case DhcpStateLeased:
    case '0':
    {
    // 0: nothing happened
    Serial.println("DHCP: nothing happened");
    break;
    }
    case '1':
    {
    // 1: renew failed
    Serial.println("DHCP: renew failed");
    break;
    }
    case '2':
    {
    // 2: renew success
    Serial.println("DHCP: renewed OK!");
    // We have a DHCP lease, so print the info
    Serial.print("ip: ");
    Serial.println(Ethernet.localIP());
    ipState = DhcpStateLeased;
    //const byte* ipAddr = EthernetDHCP.ipAddress();
    //const byte* gatewayAddr = EthernetDHCP.gatewayIpAddress();
    //const byte* dnsAddr = EthernetDHCP.dnsIpAddress();
    //Serial.print("ip: ");
    //Serial.println(ip_to_str(ipAddr));
    //Serial.print("gw: ");
    //Serial.println(ip_to_str(gatewayAddr));
    //Serial.print("dns: ");
    //Serial.println(ip_to_str(dnsAddr));
    break;
    }
    case '3':
    {
    // 3: rebind fail
    Serial.println("DHCP: rebind failed");
    break;
    }
    case '4':
    {
    // 4: rebind success
    Serial.println("DHCP: rebind success");
    // We have a DHCP lease, so print the info
    Serial.print("ip: ");
    Serial.println(Ethernet.localIP());
    ipState = DhcpStateLeased;
    break;
    }

    //}
    }
    }

    #1872
    Joe
    Participant

    Thanks for the code Squigley! I’ll give it a try.

    What I did to make sure that my Botanicalls would work perfectly was to download version 0.22 of the Arduino IDE. I customized it for my twitter feed, compiled and uploaded it. It works great. However, I would like to learn how to manage DHCP on Arduino 1.01.

    Thanks again for you help.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.


New kits are here!

Categories

Pothos Plant Tweets

    Flickr Feed

    www.flickr.com
    More photos or video tagged with botanicalls on Flickr

    Meta