Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cupcarbon/CupCarbonVersion.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cupcarbon;

public final class CupCarbonVersion {
public static final String VERSION = "IoT 5.1";
public static final String VERSION = "IoT 5.1.1 beta (Parthenope)";
public static final String YEAR = "2021";
public static final int UPDATE = 31;
}
60 changes: 60 additions & 0 deletions src/iotlab/HTTPClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package iotlab;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Client
{

/**
* ThingsBoars simple client
* user micheledicapua@gmail.com
* Sulla pagine Thingsboard aprire la dashboard IoT Lab
* @param data
*/
public static void sendInCloud(float data)
{
URL url = null;
HttpURLConnection con = null;
try
{
url = new URL ("http://demo.thingsboard.io/api/v1/ZJifi2d7hOZWhhPz3FJq/telemetry");
con = (HttpURLConnection)url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
//temperature è la chiave (KEY) del widget (lettura dati) di TensorBoard
String jsonInputString = "{\"temperature\":"+data+"}";

OutputStream os = con.getOutputStream();
byte[] input = jsonInputString.getBytes("utf-8");
os.write(input, 0, input.length);
}
catch (Exception e)
{
e.printStackTrace();
}

try
{
BufferedReader br = new BufferedReader (new InputStreamReader(con.getInputStream(), "utf-8"));
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null)
{
response.append(responseLine.trim());
}
System.out.println("Response="+response.toString());
System.out.println("Status="+con.getResponseCode());
}
catch (Exception e)
{
e.printStackTrace();
}

}
}
9 changes: 8 additions & 1 deletion src/senscript/SenScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,18 @@ public boolean isNumeric(String arg) {
}
}

/* BUG FIXED ISSUE ON GITHUB #20
public void variablesToValues(String [] args) {
for(int i=0; i<args.length; i++)
if(args[i].charAt(0)=='$')
args[i] = variables.get(args[i].substring(1));
}
}
*/

public void variablesToValues(String [] args) {
for(int i=0; i<args.length; i++)
args[i] = getVariableValue(args[i]);
}

public void setIndex(int index) {
this.index = index;
Expand Down
4 changes: 4 additions & 0 deletions src/senscript/SenScriptAddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,10 @@ public static void addCommand(String instStr, SensorNode sensorNode, SenScript s
command = new Command_CPRINT(sensorNode, inst);
}

if (inst[0].toLowerCase().startsWith("#")) {
//SKIP comment
}

//-------
// This part must be here (at the end). All new commands must be added before (above)

Expand Down
6 changes: 2 additions & 4 deletions src/senscript/SenScriptCondition_LESS.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ public boolean evaluate() {
v2 = Double.valueOf(sensor.getScript().getVariableValue(arg2));
}
catch(Exception e) {
System.err.println("[CupCarbon ERROR] (S"+sensor.getId()+"): Condition < ("+arg1+" is not a number)");
System.err.println("[CupCarbon ERROR] (S"+sensor.getId()+"): Condition < ("+arg2+" is not a number)");
}

return (v1 < v2);
}


}
}
31 changes: 31 additions & 0 deletions src/senscript_functions/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,35 @@ public static String myf(String [] args) {
return valToReturn;
}


/**
* Demo function to integrate Thingsboard sensor
* @param args
* @return
*/
public static String cloud(String [] args)
{
String valToReturn = "";

System.out.println("cloud() ARGS lenght: "+args.length);

try
{
float f = Float.parseFloat(args[0]); //DATA VALUE SENT TO THINGSBOARD

System.out.println((new java.util.Date()) +" - Called cloud() function params "+f);

System.out.println("Sending data in cloud...");

iotlab.Client.sendInCloud(f);

}
catch (Exception e)
{
System.out.println("cloud() - Wrong parameters passed. err="+e.getMessage());
System.out.println("args[0]="+args[0]);
}

return valToReturn;
}
}
6 changes: 5 additions & 1 deletion src/senscript_functions/ScriptFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ public class ScriptFunctions {
e.printStackTrace();
}
}


if(function.equals("cloud")) {
return new String [] {Functions.cloud(args), "0.0", "0.0"};
}

return new String [] {"[SCRIPT] FUNCTION ERROR: Unknown function!","0.0", "0.0"};
}

Expand Down