Hi,
Im trying to send event to the cloud when compass direction changes. However the event is only seen in the cloud just once after login. My code:
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);
azimuth = (int) ((Math.toDegrees(SensorManager.getOrientation(rotationMatrix, orientation)[0]) + 360) % 360);
if (azimuth >= 337 && azimuth <= 360 || azimuth >= 0 && azimuth <= 22) {
n = "N"; // 0 deg
try {
ParticleCloudSDK.getCloud().publishEvent("north", "N", ParticleEventVisibility.PUBLIC, 60);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
} else if (azimuth > 22 && azimuth < 68) {
n = "NE"; //45 deg
try {
ParticleCloudSDK.getCloud().publishEvent("north", "NE", ParticleEventVisibility.PUBLIC, 60);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
} else if (azimuth >= 68 && azimuth <= 112) {
n = "E"; // 90deg
try {
ParticleCloudSDK.getCloud().publishEvent("north", "E", ParticleEventVisibility.PUBLIC, 60);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
} else if (azimuth > 112 && azimuth < 157) {
n = "SE"; //135deg
try {
ParticleCloudSDK.getCloud().publishEvent("north", "SE", ParticleEventVisibility.PUBLIC, 60);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
} else if (azimuth >= 157 && azimuth <= 203) {
n = "S"; //180deg
try {
ParticleCloudSDK.getCloud().publishEvent("north", "S", ParticleEventVisibility.PUBLIC, 60);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
} else if (azimuth > 203 && azimuth < 248) {
n = "SW"; //225deg
try {
ParticleCloudSDK.getCloud().publishEvent("north", "SW", ParticleEventVisibility.PUBLIC, 60);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
}
if (azimuth >= 248 && azimuth <= 293) {
n = "W"; //270deg
try {
ParticleCloudSDK.getCloud().publishEvent("north", "W", ParticleEventVisibility.PUBLIC, 60);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
}
if (azimuth > 293 && azimuth < 337) {
n = "NW";//315deg
try {
ParticleCloudSDK.getCloud().publishEvent("north", "NW", ParticleEventVisibility.PUBLIC, 60);
} catch (ParticleCloudException e) {
e.printStackTrace();
}
}
//on the phone screen tle line below show correct info
txt_azimuth.setText("Azimuth : " + Integer.toString(azimuth) + "° " + n);
}
}
Why the events are not published on sensor change. Azimuth and N values on the phone screen work correctly.