Italian Aggiornare dati su http://pvoutput.org/service/r2/addbatchstatus.jsp

Angelo Messina

Active Member
Licensed User
Longtime User
Salve a tutti, ho la necessità di aggiornare dei dati in un server utilizzando B4A versione 7.80, ho tentato varie soluzioni compreso l'uso di #IF JAVA ma non riesco ad ottenere il risultato sperato, potete aiutarmi, in merito la stessa cosa funzioni in java in una applicazione che gira da anni su un pc adesso devo farlo con android. Grazie
B4X:
public class PVOutput
{
    private final String USER_AGENT = "PVOutput/1.4.5.1";

    int sendPost(String data,String sid, String key) throws Exception
    {
        String url = "http://pvoutput.org/service/r2/addbatchstatus.jsp";
        //data = date(yyyymmdd), time(hh:mm), energy gen, power gen, energy con, power con, temp, volt

        URL obj = new URL(url);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("POST");
        con.setRequestProperty("User-Agent", USER_AGENT);
        con.setRequestProperty("X-Pvoutput-SystemId", sid);
        con.setRequestProperty("X-Pvoutput-Apikey", key);

        con.setDoOutput(true);
        try (DataOutputStream wr = new DataOutputStream(con.getOutputStream()))
        {
            wr.writeBytes(data);
            wr.flush();
        }

        int responseCode = con.getResponseCode();

        StringBuffer response;
        try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())))
        {
            String inputLine;
            response = new StringBuffer();
            while ((inputLine = in.readLine()) != null)
            {
                response.append(inputLine);
            }
        }
        con.disconnect();
        return responseCode;
    }
}
Ho provato con HttpUtils2

ma non capisco come passare i parametri
data
data = date(yyyymmdd), time(hh:mm), energy gen, power gen, energy con, power con, temp, volt

sid = Utente
key = apiKey

Sub PVOutput

Dim PVjob As HttpJob
Dim url As String="http://pvoutput.org/service/r2/addbatchstatus.jsp"
PVjob.Initialize("PVjob",Me)
PVjob.Password=apikey
PVjob.Username=sid

PVjob.PostString( url,data)
...

B4X:
Sub JobDone (Job As HttpJob)
    ProgressDialogHide
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Dim strReturn As Int
        Log(Job.GetString)
        strReturn = Job.GetString
        Log(strReturn)
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 

Angelo Messina

Active Member
Licensed User
Longtime User
data=20180211,15:14,11.02,0015,0,0,11,220
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
** Service (httputils2service) Start **
Unauthorized 401: Invalid System ID
Unauthorized 401: Invalid System ID
JobName = Job2, Success = false
Error: Unauthorized
JobName = Job1, Success = false
Error: Unauthorized
 
Top