We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi! I am trying the following code to make my Heroku app listen to new messages, but I'm obviously missing something. Can someone help me find it?
import processing.net.*;
Client c;
String data;
void setup() {
size(200, 200);
background(50);
fill(200);
c = new Client(this, "newapp.herokuapp.com", 80); // Connect to server on port 80
c.write("GET / HTTP/1.0\r\n"); // Use the HTTP "GET" command to ask for a Web page
c.write("\r\n");
int newValue = 10;
String tempLink = "GET /api/device/mydevice/sensor/temp/report?value=";
String postDataTemp = tempLink+ newValue +" "+"HTTP/1.1";
if (c.available()>0) {
c.write(postDataTemp);
c.write("Host: newapp.herokuapp.com");
c.write("Connection: close");
String message = c.readString();
println(message);
c.stop();
}
}
void draw() {
}
Answers
Changed a couple of things, still nothing as a response:
Now I get the following:
HTTP/1.1 404 Not Found Connection: keep-alive Server: Cowboy Date: Thu, 06 Nov 2014 12:53:03 GMT Content-Length: 2960 Content-Type: text/html; charset=utf-8 Cache-Control: no-cache, no-store
There is no issue with your Processing Code whatsoever. My guess would be that your issue lies with Hirokuapp (or how you understood their api) and not with Processing. Maybe you should take a closer look at the Server response:
There is no app configured at that hostname. Perhaps the app owner has renamed it, or you mistyped the URL.
By the way, since it's only a GET command, you can try this on your Browser too: newapp.herokuapp.com/api/device/mydevice/sensor/temp/report?value= newapp.herokuapp.com/api/device/mydevice/sensor/temp/report?value=1
The link points to nowhere - this isn't the name of the app.
However, when I post the correct link in a browser, data are received just fine in the app (values are updated). I still haven't been able to use Processing for this job...
aaaaaaahhhhhh.....!!!!!!! Found the bug!
Instead of: c.write("Host: "+myserver+" \r\n");
It had to be: c.write("Host: "+myserver+"\r\n");
Get it?
:-)
ah, there you go. :)