POST requests to Particle Photon in Processing (HTTP Requests library)

So I'm trying to do a simple POST to my Particle Photon, in HTML the post looks like this:

      <form action="" method="POST">
        Tell your device what to do!<br>
        <input type="radio" name="args" value="on">Turn the LED on.
        <input type="radio" name="args" value="off">Turn the LED off.
        <input type="submit" value="Do it!">

I'm trying to use the [](HTTP Requests library) (version 0.1.2 because 0.1.3 is buggy). And my code looks like this:

import http.requests.*;

public void setup() {
  size(500, 500);
  PostRequest post = new PostRequest("");
  post.addData("args", "on");
  System.out.println("Reponse Content: " + post.getContent());
  println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));

It works fine in the HTTP version, but I can't get Processing talking. Any advice??


  • edited October 2016

    Hey Scott, did you get this to work in the end?

    I've been trying to do send POST requests to my Photon Particle, but haven't had much success.

    I'm using the HTTP Requests for Processing library and here's what my POST requests are looking like:

    PostRequest post = new PostRequest("");
    post.addData("access_token", "xxx");
    post.addData("args", "on");

    It crossed my mind that the library may not support HTTPS.

  • I'll answer my own question. I was able to communicate with the device with the following code:

    void postReq(String value) {
      String httpsURL = "";
      try {
        String query = "access_token=xxx"; 
        query += "&";
        query += "args="+value ;
        URL myurl = new URL(httpsURL);
        HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
        con.setRequestProperty("Content-length", String.valueOf(query.length())); 
        con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 
        con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0;Windows98;DigExt)"); 
        DataOutputStream output = new DataOutputStream(con.getOutputStream());  
        DataInputStream input = new DataInputStream( con.getInputStream() ); 
        for ( int c = (); c != -1; c = ) 
          System.out.print( (char)c ); 
        System.out.println("Resp Code: "+con.getResponseCode()); 
        System.out.println("Resp Message: "+ con.getResponseMessage());
      catch(IOException e) {
Sign In or Register to comment.