public Integer update(Object[] data) { String result = "0"; try { if (System.currentTimeMillis() - lastUpdate < intervalSeconds * 1000) { log.debug(String.format("not ready for posting - must be >= %d seconds", intervalSeconds)); return 0; } if (data.length > 8) { log.warn("data array is larger than 8 - post will be truncated"); } StringBuffer url = new StringBuffer(); url.append(String.format("%s?key=%s", updateURL, writeKey)); for (int i = 0; i < data.length && i < 8; ++i) { Object o = data[i]; url.append(String.format("&field%d=%s", i + 1, o.toString())); } HTTPRequest request = new HTTPRequest(url.toString()); result = request.getString(); log.info(String.format("ThingSpeak returned %s", result)); } catch (IOException e) { Logging.logError(e); } Integer ret = Integer.parseInt(result); if (ret > 0) { lastUpdate = System.currentTimeMillis(); } return ret; }
public static void main(String[] args) { LoggingFactory.getInstance().configure(); LoggingFactory.getInstance().setLevel(Level.DEBUG); try { // FIXME !!! - don't use Adafruit's library - do your own stepper control through "pure" // MRLComm.ino AdafruitMotorShield fruity = (AdafruitMotorShield) Runtime.createAndStart("fruity", "AdafruitMotorShield"); Runtime.createAndStart("gui01", "GUIService"); fruity.connect("COM3"); Motor motor1 = fruity.createDCMotor(4); motor1.move(0.4f); // create a 200 step stepper on adafruitsheild port 1 Stepper stepper1 = fruity.createStepper(200, 1); // FIXME - needs to be cleaned up - tear down fruity.releaseStepper(stepper1.getName()); // Runtime.createAndStart("python", "Python"); } catch (Exception e) { Logging.logError(e); } }
public static void main(String[] args) { LoggingFactory.getInstance().configure(); LoggingFactory.getInstance().setLevel(Level.DEBUG); try { // BasicConfigurator. log.info("hello"); ThingSpeak thingSpeak = new ThingSpeak("thingSpeak"); thingSpeak.update(33); thingSpeak.startService(); /* * GUIService gui = new GUIService("gui"); gui.startService(); */ } catch (Exception e) { Logging.logError(e); } }
public static void main(String[] args) { LoggingFactory.getInstance().configure(); LoggingFactory.getInstance().setLevel(Level.INFO); try { MyoThalmic myo = (MyoThalmic) Runtime.start("myo", "MyoThalmic"); myo.test(); Hub hub = new Hub("com.example.hello-myo"); System.out.println("Attempting to find a Myo..."); log.info("Attempting to find a Myo"); Myo myodevice = hub.waitForMyo(10000); if (myodevice == null) { throw new RuntimeException("Unable to find a Myo!"); } System.out.println("Connected to a Myo armband!"); log.info("Connected to a Myo armband"); DataCollector dataCollector = new DataCollector(); hub.addListener(dataCollector); while (true) { hub.run(1000 / 20); // System.out.print(dataCollector); System.out.println("yaw is " + dataCollector.getYaw()); System.out.println("roll is " + dataCollector.getRoll()); System.out.println("pitch is " + dataCollector.getPitch()); Runtime.start("gui", "GUIService"); } } catch (Exception e) { Logging.logError(e); } }