Creating inputs in emoncms via java

Hi, i have a problem with the create input in the emoncms. The emoncms is installed in localhost(windows with wampserver).
I have a arduino that send data for emoncms through java application. I use the notebook for connection.
The problem is that i can’t create of the inputs.
The return is a json: {“success”:false,“message”:“Username or password empty”}

The utilized code is:

public static void enviar(String mensagem) {
		
  try {
      URI uri = new URIBuilder()
	 .setScheme("http")
	 .setHost("localhost")
	 .setPath("/emoncms/input/post.json")
	 .addParameter("node=","1")
	 .addParameter("json=",mensagem)
	 .addParameter("apikey=",apikey)
	 .build();

      DefaultHttpClient client = new DefaultHttpClient();
			
	HttpPost httpget = new HttpPost( uri );
	HttpResponse response = client.execute(httpget);
	
	InputStreamReader inputReader = new InputStreamReader(response.getEntity().getContent());

	BufferedReader bufferedReader = new BufferedReader( inputReader );

	String linha = "";

	  while ( (linha = bufferedReader.readLine()) != null){
		System.out.println(linha);
	  }
    
    } catch (Exception e) {
     
     System.err.println("Erro ao enviar mensagem para o emoncms. " + e.getMessage());
     e.printStackTrace();
    } 
}

Can someone help?
Thanks!

I have used the following ‘not really java’ code in the Processing Language to send data to emoncms.org and a local host. The string etherPacket is assembled with the data.

    String hostname = "emoncms.org";
    chttp = new Client(this, "emoncms.org", 80); // Connect to server on port 80  
        
   String etherPacket = "[[0,20,"+Integer.toString(icekwmeter)+
                        ","+Integer.toString(icekwavg)+
                        ","+Integer.toString(psMeter)+
                        ","+Integer.toString(powerAvail)+
                        ","+Integer.toString(rawsstap)+
                        ","+Integer.toString(emmDemand)+
                        ","+Integer.toString(demandNow)+
                        ","+Integer.toString(demandValle)+
                        ","+Integer.toString(demandPeak)+
                        ","+Integer.toString(demandNoche)+
                        ","+Integer.toString(icewattmeter)+"]]";    
    
    chttp.write("GET /input/bulk.json?data="+etherPacket+"&apikey=myapikey HTTP/1.1 \r\n"); 
    chttp.write("Host: " + hostname + "\r\n");     
    chttp.write("Accept: */*\r\n");
    chttp.write("User-Agent: Java\r\n"); 
    chttp.write("\r\n");    
    
    System.out.println("sent to emoncms");

Thanks Kelvin by help me!

The code I posted above has worked fine for 3+ years. It stopped working 3 days ago. Problem 1 was insufficient funds in the account. Took care of that problem. Data is not getting to the feed page. I can send data using a browser but not with the ‘java’ program. Any ideas where to look for the problem?

@TrystanLea - could this be related to the server move?

Trystan and Brian,

Any idea why the GET from a java program would stop working after the server move?

I can send data from a browser and the feed gets updated. Send what I believe to be the same and it is not showing up on the feeds page.

Is the User-Agent header being filtered at the server?

Can you please tell me if there are any required headers?

Sincerely,

Kevin

I don’t have any dealings with emoncms.org I’m afraid. I’d take out some of the 'forced parameters (like port and user agent and see if it works.