Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: exception #3

Merged
merged 1 commit into from
Oct 13, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,12 @@ public class MappingDevicesListener {
private MqttH2StorageController mqttH2Storage;

public void onBind(ServiceReference ref) {
printlnDebug("Bound service: " + ref);

this.mqttH2Storage.setFlag(true);

this.mqttPublisher.sendFlowRequestBySensorDevice();
this.mqttH2Storage.subscribeDevicesTopics();
}

public void onUnbind(ServiceReference ref) {
printlnDebug("Unbound service: " + ref);

this.mqttH2Storage.setFlag(true);
}

private void printlnDebug(String str) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package br.ufba.dcc.wiser.soft_iot.local_storage;

import br.uefs.larsid.extended.mapping.devices.services.IDevicePropertiesManager;
import br.ufba.dcc.wiser.soft_iot.entities.Device;
import br.ufba.dcc.wiser.soft_iot.entities.Sensor;
import br.ufba.dcc.wiser.soft_iot.entities.SensorData;
import br.ufba.dcc.wiser.soft_iot.mapping_devices.Controller;
import br.ufba.dcc.wiser.soft_iot.tatu.TATUWrapper;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
Expand All @@ -24,7 +22,6 @@
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
import org.json.JSONObject;
import org.osgi.service.blueprint.container.ServiceUnavailableException;

public class MqttH2StorageController implements MqttCallback {
Expand All @@ -43,8 +40,6 @@ public class MqttH2StorageController implements MqttCallback {
private int defaultCollectionTime;
private int defaultPublishingTime;
private boolean debugModeValue;
private IDevicePropertiesManager deviceManager;
private boolean flag = false;

public void init() {
MqttConnectOptions connOpt = new MqttConnectOptions();
Expand Down Expand Up @@ -176,8 +171,6 @@ public void run() {
printlnDebug("topic: " + topic + " message: " + messageContent);
if (TATUWrapper.isValidTATUAnswer(messageContent)) {
try {
flag = false;

printlnDebug("valid TATU answer");
String deviceId = TATUWrapper.getDeviceIdByTATUAnswer(
messageContent
Expand Down Expand Up @@ -222,35 +215,6 @@ public void run() {
} catch (ServiceUnavailableException e) {
e.printStackTrace();
}
} else if (messageContent.contains("FLOW VALUE") && !flag) {
String sensorId = messageContent.split(" ")[2];
String deviceId = topic.split("/")[1];

Device device = fotDevices.getDeviceById(deviceId);

try {
int stringIndex = messageContent.indexOf("{");
JSONObject json = new JSONObject(
messageContent.substring(stringIndex)
);

int collection_time = json.getInt("collect");
int publishing_time = json.getInt("publish");

/* Altera o valor do 'collect' e 'publish'. */
device
.getSensorbySensorId(sensorId)
.setCollection_time(collection_time);
device
.getSensorbySensorId(sensorId)
.setPublishing_time(publishing_time);

/* Atualiza o dispositivo no soft-iot-mapping-devices */
deviceManager.removeDevice(deviceId);
deviceManager.addDevice(device);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Expand Down Expand Up @@ -439,20 +403,4 @@ public void setDefaultPublishingTime(int defaultPublishingTime) {
public void setDebugModeValue(boolean debugModeValue) {
this.debugModeValue = debugModeValue;
}

public void setDeviceManager(IDevicePropertiesManager deviceManager) {
this.deviceManager = deviceManager;
}

public void setSubscriber(MqttClient subscriber) {
this.subscriber = subscriber;
}

public void setNumOfHoursDataStored(String numOfHoursDataStored) {
this.numOfHoursDataStored = numOfHoursDataStored;
}

public void setFlag(boolean flag) {
this.flag = flag;
}
}
5 changes: 0 additions & 5 deletions src/main/resources/OSGI-INF/blueprint/blueprint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
</reference-listener>
</reference>

<reference
id="deviceManagerService"
interface="br.uefs.larsid.extended.mapping.devices.services.IDevicePropertiesManager"
/>

<bean id="busObj" class="br.ufba.dcc.wiser.soft_iot.local_storage.MqttPublisherController"
init-method="init" destroy-method="destroy">
Expand All @@ -62,7 +58,6 @@
<property name="numOfHoursDataStored" value="${NumberOfHoursDataStored}" />
<property name="fotDevices" ref="connectedDevices" />
<property name="debugModeValue" value="${debugMode}" />
<property name="deviceManager" ref="deviceManagerService"/>
</bean>

<bean id="LocalDataControllerBean" class="br.ufba.dcc.wiser.soft_iot.local_storage.LocalDataControllerImpl">
Expand Down