Comments (10)
There are a couple of ways you can do this with SiteWhere. One approach is to have the device make a call to the REST services at an interval and ask for the last 10 minutes of events. There are REST methods for querying based on time period for both assignments and for sites. See the REST docs for an example:
http://documentation.sitewhere.org/rest/single.html#listMeasurements
The other approach is to live stream the data to the devices, in which case the 10 minute interval would not apply, but you would always see the latest data. You can use the MQTT outbound processor to send all events to devices that are interested. They just need to subscribe to the topic you broadcast on. See this documentation for more information:
http://documentation.sitewhere.org/userguide/tenant/event-processing.html#mqtt-event-processor
The part about sending all data every 10 minutes would only work with polling, but live streaming would make sure the latest data is always on the client.
from sitewhere.
tnx for your response.
but i want use mqtt , and before send data to devices i should process data then send them to devices,
i thinks should use hazelcast, but i don't any idea about hazelcast...
how process data??? how send data from hazelcast to devices???
from sitewhere.
If you use the approach with the outbound MQTT processor, the data will be processed and then routed to the queue afterward. If you want to use Hazelcast, you would need a device capable of running Java and enough memory (over 400k) to run the Hazelcast client.
from sitewhere.
hi again
i know that , but how i can process data in sitewhere before send data by mqtt?? i don't any idea!!!!
and sitewhere explanation is very week (lack of document).
can i use java project like air-traffic example, for fetch data from mongoDB and process that, then forward data over mqtt to devices?how i can do it??
or i should use Mule AnyPoint Platform??
or use from Apache Spark???
which one i should use that??
which one is better for my oroblem??
Realy I am confused .
your response and documents is very generally :(
from sitewhere.
tnx for your help
could you please help me.now i'm waiting for your response.
do you Any answers for me???
from sitewhere.
If you are looking to add processing logic before sending data back out over MQTT, take a look at the Raspberry Pi demo which applies conditional logic and creates new events in response to inbound data:
http://documentation.sitewhere.org/tutorials/rpi/node-red-dht11-logic.html
The general flow is:
- SiteWhere brings in data via event sources.
- SiteWhere stores data and hands it off to outbound pipeline.
- Groovy processor applies logic (possibly creates new events or other system objects)
- MQTT outbound processor (or Hazelcast, etc) sends data to interested parties.
from sitewhere.
hi again
i use below code for send command from sitewhere to to device , but i don't know , where i should set tenant??????
getTenant return null..
please help me to correct for logic code, because i wrote this code base my suggestion
public class test extends TenantLifecycleComponent {
private static ISite site;
private static int maxCount = 100;
private static DeviceAssignment device;
private static IDeviceManagement dm;
private static IDeviceEventManagement dem;
private static SiteWhereClient siteWhereClient;
private static final String SITE_ID = "1d9e9a2e-4594-44ea-ac02-2e8adcd8f866";
private static Map<String, String> parameters = new HashMap<String, String>();
private static MQTT mqtt;
private static FutureConnection connection;
public static void main(String[] args) throws SiteWhereException {
siteWhereClient = new SiteWhereClient("http://localhost:8081/sitewhere/api/", "admin", "password");
System.out.println(siteWhereClient.getTenantAuthToken());
if (waitForSiteWhereToStart()) {
test t = new test(LifecycleComponentType.System);
t.start();
}
DeviceActions deviceActions = new DeviceActions(dm, dem);
DeviceLocationSearchResults result = siteWhereClient.listDeviceLocations(SITE_ID, maxCount);
List<DeviceLocation> locations = result.getResults();
MqttCommandDestination mqttCommandDestination = new MqttCommandDestination();
// IDeviceManagement dm = SiteWhere.getServer().
try {
MQTT mqtt = new MQTT();
mqtt.setHost("localhost", 1883);
connection = mqtt.futureConnection();
Future<Void> future = connection.connect();
future.await(3, TimeUnit.SECONDS);
System.out.println("Connected to: " + mqtt.getHost());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
for (DeviceLocation location : locations) {
parameters.clear();
parameters.put("lat", location.getLatitude().toString());
parameters.put("lng", location.getLongitude().toString());
parameters.put("speed", "20");
try {
deviceActions.sendCommand(location.getDeviceAssignmentToken(), "TrafficData", parameters);
} catch (Exception e) {
throw new SiteWhereException("Unable send data", e);
}
System.out.println(location.getLatitude());
}
if (connection != null) {
connection.disconnect();
}
}
protected static boolean waitForSiteWhereToStart() {
while (true) {
try {
siteWhereClient.getSiteWhereVersion();
return true;
} catch (Throwable e) {
LOGGER.info("Waiting on SiteWhere REST services to become available.", e);
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
LOGGER.error("Interrupted while waiting for SiteWhere to start.");
return false;
}
}
}
public test(LifecycleComponentType type) {
super(type);
}
/*
* (non-Javadoc)
*
* @see com.sitewhere.spi.server.lifecycle.ILifecycleComponent#start()
*/
@Override
public void start() throws SiteWhereException {
ITenant tenant1 = getTenant();
System.out.println(tenant1);
dm = SiteWhere.getServer().getDeviceManagement(getTenant());
dem = SiteWhere.getServer().getDeviceEventManagement(getTenant());
if (dm == null) {
throw new SiteWhereException(
"Registration manager auto assignment site token is invalid.");
}
}
/*
* (non-Javadoc)
*
* @see com.sitewhere.spi.server.ITenantAware#getTenant()
*/
/*
* (non-Javadoc)
*
* @see com.sitewhere.spi.server.lifecycle.ILifecycleComponent#getLogger()
*/
@Override
public Logger getLogger() {
return LOGGER;
}
/*
* (non-Javadoc)
*
* @see com.sitewhere.spi.server.lifecycle.ILifecycleComponent#stop()
*/
@Override
public void stop() throws SiteWhereException {
}
}
from sitewhere.
Is this code running on the Android device? If so, are you using the Android SDK, because it already takes care of the connection to MQTT and the messaging to the server. There is support for sending the standard types of data such as measurements, locations, and alerts, as well as acknowledging commands sent to the device. The protocol used is documented here:
http://documentation.sitewhere.org/userguide/sending-data.html
but the SDK takes care of all of the communication for you.
If you want to invoke a device command from a device, you would have to use the REST services since it's not supported via MQTT right now. Instead, you would need to make a direct REST call to create a device command invocation as shown here:
http://documentation.sitewhere.org/rest/single.html#createCommandInvocation
You are extending TenantLifecycleComponent which is only intended for internal SiteWhere components running on the server, so nothing related to the lifecycle will work. You also will not have access to SiteWhere.getServer() since that code only works for components running inside SiteWhere itself. From a device standpoint, you should always interact via the protocol, which in this case would be MQTT or REST.
The previous posts indicated you wanted to stream commands from the SiteWhere to interested devices via MQTT. In that case, you need to configure the outbound MQTT processor to send to a topic, then use logic like we use in the Android example application to receive the MQTT events on the devices:
from sitewhere.
tnx for your response
but this code running on the severer( like AirTaraffic example) and my problem is on server side because i want send data from sitewhere to devices by java code.
i want send location data which saved on database to devices over Mqtt but i don't know ,how i can do it? how to send processed data to devices through sitewhere?if my code doing that, where i should set tenant??????getTenant return null..
i dont know how to get tenant?
which class i should extend?
from sitewhere.
hi derekadams
do you have any response for me? because i'm stopped in this state, and waiting for your help.
tanks for your response.
from sitewhere.
Related Issues (20)
- future isn't success, cause: (org.apache.zookeeper.ClientCnxnSocketNetty) [nioEventLoopGroup-2-1] java.nio.channels.ClosedChannelException
- WARN fsync-ing the write ahead log in SyncThread:2 took 3932ms which will adversely effect operation latency. File size is 67108880 bytes
- What is the purpose of spring native support v3.1.0 HOT 1
- How to deploy a highly reliable production environment instead of swctl deploying all services in a cluster HOT 2
- License, documentation, and developer resource concerns HOT 5
- stat /bin/grpc_health_probe: no such file or directory": unknown
- I want Sitewhere to support other relational databases besides the default database postgres95. Can you give me some suggestions? HOT 7
- javax.enterprise.inject.spi.DeploymentException: No config value of type HOT 1
- 3.1.0 will probably be released more
- Why doesn't the device have a name HOT 2
- swctl:v0.9.2 Debug mode cannot be turned on
- V3.0 can't add tenant HOT 1
- How to optimize Kafka messages with serious accumulation?
- helm install failed
- Cannot deploy sitewhere using HELM - Pods are failing with Error: SRCFG00014: Property sitewhere.config.k8s.pod.ip not found HOT 2
- How can I quickly add two microservices
- swctl create instance sitewhere failed
- Excellent open-source gentleman, noticed that the sitewhere project has not been updated for more than a year HOT 2
- Is there any simplified installation guide?
- Job cannot call the event management service
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sitewhere.