Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package de.root1.logiccollection; import de.root1.kad.knxservice.KnxServiceException; import de.root1.kad.logicplugin.Logic; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.Socket; import java.util.Timer; import java.util.TimerTask; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; /** * * @author achristian */ public class offLogicVocESP8266 extends Logic { String ga = "VOC ESP8266"; TimerTask tt; Timer t = new Timer("VOC ESP8266 reader"); @Override public void init() { this.tt = new TimerTask() { @Override public void run() { try { Socket s = new Socket("nodemcu1", 44444); OutputStream out = s.getOutputStream(); InputStream in = s.getInputStream(); out.write("\n".getBytes()); out.flush(); InputStreamReader isr = new InputStreamReader(in); JSONObject data = (JSONObject) JSONValue.parse(isr); isr.close(); out.close(); int voc = Integer.parseInt(data.get("voc").toString()); int tvoc = Integer.parseInt(data.get("voc").toString()); int resistance = Integer.parseInt(data.get("resistance").toString()); int status = Integer.parseInt(data.get("status").toString()); log.info("voc={}, tvoc={} resistance={} status={}", new Object[] { voc, tvoc, resistance, status }); // write(ga, String.valueOf(voc)); } catch (IOException ex) { ex.printStackTrace(); } } }; setPA("1.1.203"); t.schedule(tt, 5000, 60000); log.info("VOC ESP8266 reader is running."); } }