Unit 3: Simulating the Device Measuring Point Data¶
After the battery device is connected to EnOS Cloud, you can simulate the temperature data of the battery using the EnOS Device SDK and upload the simulated data to EnOS Cloud. Refer to the steps below.
Declare the following main functions for simulating the device data.
public static void main(String[] args) throws Exception { initWithCallback(); alwaysPostMeasurepoint(); }
Use the
alwayspostMeasurepoint
function to simulate the posting of random battery temperature data repeatedly.public static void alwaysPostMeasurepoint() throws Exception { while(true) { long ts = System.currentTimeMillis(); Random random = new Random(); System.out.println("start post measurepoint ..."); MeasurepointPostRequest request = MeasurepointPostRequest.builder().addMeasurePoint("temperature", random.nextDouble()).build(); try { client.fastPublish(request); System.out.println(" post measurepoint success..."); } catch (Exception var3) { var3.printStackTrace(); } System.out.println(client.isConnected() + " post cost " + (System.currentTimeMillis() - ts) + " millis"); Thread.sleep(10000L); } }
If you want to simulate the data of other measurement points, define the measurement point name in the
addMeasurePoint
function.Check the running result of the program. The program will simulate random battery temperature data according to the specified time interval in milliseconds and upload the data to EnOS Cloud.
Open the Device Details page of the battery1 device, click Measurement Points, and view the simulated temperature data of the battery.
Click to go to the Data Insights page, where you can view the latest data of the temperature measurement point.