0

can't send feed data to feed
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

can't send feed data to feed

by mvernooy on Sun Feb 14, 2021 6:35 pm

Hi,

I'm a beginner on Arduino and Adafruit IO.
I'm trying to send data to my feed with a W600 Grove connected to my Arduino Uno.
The serial monitor shows I'm connected to wifi and data is send, but nothing comes up on my feed. I checked the key and feed name several times.

I use the following code, an example from the GITHUB. Can anyone tell me whats's wrong? Is it in the wifi.httpPost part?

Code: Select all | TOGGLE FULL SIZE
/*
  Demonstrates how to connect the W600 module to a wifi access point and send some data to AdafruitIO via httpPost.

  created 12 Oct, 2019
  by Finn Lattimore

  This example code is in the public domain.
 */
#include "w600.h"
#if defined(HAVE_HWSERIAL1)
  #define WifiSerial Serial1
#elif defined(ARDUINO_SEEED_ZERO)
  //the different board of samd have different serialx
  #define WifiSerial Serial2   //serial number of seeeduino_zero (compatible with Wio Lite W600)
#elif defined(SEEED_XIAO_M0)
    #define WifiSerial Serial1   
#else
  SoftwareSerial WifiSerial(2,3);
#endif

#define SERIAL Serial
#define debug  SERIAL

AtWifi wifi;

const char *TARGET_IP   = "\"io.adafruit.com\""; // This is the IP address for AdafruitIO
uint16_t TARGET_PORT = 80;
uint16_t LOCAL_PORT  = 1234;


int connect_to_AP(int retries){
  bool ssid_set = false;
  bool psswd_set = false;
  bool joined = false;
  int attempt = 0;
  debug.println(F("setting ssid ..."));
  while (!ssid_set && attempt < retries){
      ssid_set = wifi.wifiStaSetTargetApSsid(F("ssid_for_wifi_access_point")); //TODO put in access point name here
      delay(150);
  } if (!ssid_set){
    debug.println(F("failed to set ssid"));
    return 0;
  }
 
  attempt = 0;
  debug.println(F("setting password"));
  while (!psswd_set && attempt < retries){
    psswd_set = wifi.wifiStaSetTargetApPswd(F("password_for_wifi_access_point")); //TODO put in access point password here
    delay(150);
  } if (!psswd_set){
    debug.println(F("failed to set password"));
    return 0;
  }

  attempt = 0;
  while (!joined && attempt < retries){
      joined = wifi.sendAT(F("AT+WJOIN")); //join network
      delay(1500);
  } if (!joined){
      debug.println(F("failed to join network"));
      return 0;
  }

  debug.println(F("connected to AP"));
  return 1;
}


char value[] = "value=44.6\n\n"; // the data to post
int socket = -1;
void setup()
{
    debug.begin(115200);
    wifi.begin(WifiSerial,9600);

    configure_wifi(5);
    connect_to_AP(5);
    socket = create_socket(5);
 
    wifi.httpPost(
      socket,
      F("POST /api/v2/your_username/feeds/your_feed/data HTTP/1.1\n"), //TODO replace your_username and your_feed with the corresponding values from AdafruitIO
      F("Host: io.adafruit.com\n"),
      F("User-Agent: arduino\n"),
      F("Content-Type: application/x-www-form-urlencoded\n"),
      F("Accept: */*\nX-AIO-Key: your_X-AIO-Key\n"), //TODO put in your_X-AIO-Key from AdafruitIO
      value
    );     
}

void loop()
{
  delay(2000);   
}

int create_socket(int retries){
  int socket = -1;
  for (int attempt = 0; attempt < retries; attempt ++){
    debug.print(F("Creating socket to remote server, attempt:"));debug.println(attempt+1);
    socket = wifi.wifiCreateSocketSTA(TCP,Client,TARGET_IP,TARGET_PORT,LOCAL_PORT);
    if (socket >= 0) {
      debug.print(F("connected to remote server. Socket="));debug.println(socket);
      delay(400);
      return socket;
    }
    delay(1000);
  }
  debug.println(F("failed to connect to remote server"));
  return socket;
}

void configure_wifi(int retries){
  for (int attempt = 0; attempt < retries; attempt ++) {
    debug.print(F("Configuring wifi, attempt:")); debug.println(attempt + 1);
    wifi.sendAT(F("AT+Z")); //wifi_reset
    delay(1500);
    if (wifi.wifiSetMode(STA)){
      debug.println(F("wifi configured"));
      delay(100);
      return;
    }
  }
  debug.println(F("wifi configuration failed"));
}
Last edited by franklin97355 on Sun Feb 14, 2021 7:53 pm, edited 1 time in total.
Reason: Added code tags for readability

mvernooy
 
Posts: 4
Joined: Mon Feb 08, 2021 5:46 pm

Re: can't send feed data to feed

by brubell on Mon Feb 15, 2021 10:59 am

Code looks like its using the correct HTTP request format (https://io.adafruit.com/api/docs/#create-data). Make sure you're using the feed KEY and not the feed name in the HTTP POST.

brubell
 
Posts: 1377
Joined: Fri Jul 17, 2015 10:33 pm

Re: can't send feed data to feed

by mvernooy on Mon Feb 15, 2021 12:03 pm

Thank you,

I used this line:
F("POST /api/v2/myname/feeds/mykey/data HTTP/1.1\n"),

In this example I used
username: myname
feed key : mykey


but it still doesn't work. Nothing comes up at my feed.
There is just one example I can find for Seeed W600 Grove....

mvernooy
 
Posts: 4
Joined: Mon Feb 08, 2021 5:46 pm

Re: can't send feed data to feed

by brubell on Wed Feb 17, 2021 12:18 pm

Where did you find this example?

brubell
 
Posts: 1377
Joined: Fri Jul 17, 2015 10:33 pm

Re: can't send feed data to feed

by mvernooy on Wed Feb 17, 2021 2:16 pm

https://github.com/Seeed-Studio/Seeed_A ... g_data.ino

this is the only example I can find.

mvernooy
 
Posts: 4
Joined: Mon Feb 08, 2021 5:46 pm

Re: can't send feed data to feed

by brubell on Fri Feb 19, 2021 11:40 am

On this line:

Code: Select all | TOGGLE FULL SIZE
      F("Accept: */*\nX-AIO-Key: your_X-AIO-Key\n"), //TODO put in your_X-AIO-Key from AdafruitIO



Did you replace your_X-AIO-Key with your credentials?

brubell
 
Posts: 1377
Joined: Fri Jul 17, 2015 10:33 pm

Re: can't send feed data to feed

by mvernooy on Fri Feb 19, 2021 12:12 pm

Yes, I'd put my key there.

mvernooy
 
Posts: 4
Joined: Mon Feb 08, 2021 5:46 pm

Re: can't send feed data to feed

by brubell on Mon Feb 22, 2021 10:26 am

I'm not sure then - the API call to Adafruit IO is correct. I'd first ensure you can connect to the internet and GET/POST websites. You will need to contact SEEED for information on how to test this since we do not sell this product.

brubell
 
Posts: 1377
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.