Author Topic: HTTP Requests from Oak  (Read 1200 times)


  • Newbie
  • *
  • Posts: 1
HTTP Requests from Oak
« on: May 15, 2017, 02:11:23 pm »
Trying hard to make an Oak project that allows me to sense a light level and upload it to the cloud. I am looking to just do data logging to an SQL database and so I wrote this whole API on the server end. I cannot find anywhere online explicit instructions on making a basic http request from Oak via the built-in WiFi. I have experience doing this with Arduino and various WiFi boards but every time I try to install the Particle HTTPClient library I get errors. Is there an alternative way to initialize my connection?


  • Jr. Member
  • **
  • Posts: 87
Re: HTTP Requests from Oak
« Reply #1 on: May 16, 2017, 08:01:03 am »
I did something similar with an online service called Carriots,2234.0.html

From what I remember, some of the basics are:

Code: [Select]
#include "ESP8266WiFi.h"

IPAddress server(82,223,244,60);  //desired  IP Address

WiFiClient client;

void sendStream()

  if (client.connect(server, 80)) {   // If there's a successful connection to the IP address on port 80
    // Make a HTTP request
    client.println("POST /streams HTTP/1.1");
    client.println("Accept: application/json");
    client.println("User-Agent: Arduino-Carriots");
    client.println("Content-Type: application/json");
    client.print("carriots.apikey: ");
    client.print("Content-Length: ");
    int thisLength = json.length();
    client.println("Connection: close");

  else {
    // If you didn't get a connection to the server:
    Particle.publish("Status", "connection failed");


  • Hero Member
  • *****
  • Posts: 867
Re: HTTP Requests from Oak
« Reply #2 on: May 16, 2017, 06:32:28 pm »
That looks to be the basics of what one of my nodes does when posting data to thingspeak... I hacked away most of the stuff that is sensor or peculiar to my coad... so should be left mostly with just the remains necessary to do the wifi talk to server bit.

Code: [Select]
WiFiClient client;

String myWriteAPIKey = "";   // Put your API key here
String fieldToPost = "field1";               // Put the field to update here
const char * server_ip = "";
const char * server_dns = "";

void setup(void)
  Particle.publish("oak/userrom/startup", "DS18x20_Particle_Thingspeak v0.6", 60, PRIVATE);

void loop(void)

// thingspeak needs minimum 15 sec delay between updates
boolean updateThingspeak(String field, float data)
  //try through DNS first
  if (client.connect(server_dns, 80))
    //construct ThinkSpeak POST URL
    String postStr = myWriteAPIKey;
    postStr += "&";
    postStr += field;
    postStr += "=";
    postStr += String(data);
    postStr += "\r\n\r\n";

    client.print("POST /update HTTP/1.1\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + myWriteAPIKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");


    return true;
  } // END if(client.connect())
      return false; //failed to connect