ONVIF: Listing all hostname of IP cameras in same network - rtsp

DiscoveryManager manager = new DiscoveryManager();
manager.setDiscoveryTimeout(10000);
manager.discover(new DiscoveryListener() {
#Override
public void onDiscoveryStarted() {
System.out.println("Discovery started");
}
#Override
public void onDevicesFound(List<Device> devices) {
for (Device device : devices)
System.out.println("Devices found: " + device.getHostName());
}
});
I am using above code for get all host names of IP cameras, One thing I wish to mention before describe my problem. I am using IP webcam android app to make my mobile act like IP cam. With this setup above code give all host names. But this snippet didn't give the actual IP camera's hostname. thank you in advance.

This code is using the Onvif protocol. But IP webcam android app may not be a Onvif device, so this device can not communicate with your the code.
This like:
You are British, I am Vietnamese. You say "What you name?", I don't understand. I need learn English. Like your IP webcam need setup Onvif protocol.

Hello guys here is the solution for this question.
public class OnvifMediaURL {
OnvifManager manager = new OnvifManager();
public void mediaURlFinder(String string) {
OnvifDevice device = new OnvifDevice(string);
manager.getServices(device, new OnvifServicesListener() {
#Override
public void onServicesReceived(#NotNull OnvifDevice onvifDevice, OnvifServices paths) {
}
});
manager.getDeviceInformation(device, new OnvifDeviceInformationListener() {
#Override
public void onDeviceInformationReceived(#NotNull OnvifDevice device,
#NotNull OnvifDeviceInformation deviceInformation) {
// TODO Auto-generated method stub
}
});
manager.getMediaProfiles(device, new OnvifMediaProfilesListener() {
#Override
public void onMediaProfilesReceived(#NotNull OnvifDevice device,
#NotNull List<OnvifMediaProfile> mediaProfiles) {
manager.getMediaStreams(device, mediaProfiles.get(0), new OnvifMediaStreamURIListener() {
#Override
public void onMediaStreamURIReceived(#NotNull OnvifDevice device,
#NotNull OnvifMediaProfile profile, #NotNull String uri) {
// TODO Auto-generated method stub
System.out.println("URL " + uri); //Printing RTSP URL
}
});
}
});
}
}
Pass the hostname, username and password you got from OnvifDiscovery to the mediaURlFinder( ) method, and it will gie you the RTSP link and you can get some other details like manufacturer, serial number etc..
I want mention that in my case I use my mobile phone as IP camera (using IP Webcam application ) and this code gave RTSP link.

Related

Android Studio - Cannot Connect to Bluetooth Device

Well, I have everything set up to create a connection to another bluetooth device.
I have a ListView that shows me devices that are paired to my bluetooth device and when I click on the desired device within the listView it should connect to it, but somehow the connection is not being established.
Here is a sample of my paired devices List:
public void getPairedDevices(){
pairedDevices = myBluetoothAdapter.getBondedDevices();
pairedDevices_ArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1);
if(pairedDevices.size()>0){
for(BluetoothDevice device : pairedDevices){
pairedDevices_ArrayAdapter.add(device.getName()+"\n"+device.getAddress());
}
}
pairedDevices_ListView.setAdapter(pairedDevices_ArrayAdapter);
pairedDevices_ListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String i = ((TextView) view).getText().toString();
String address = i.substring(i.length() - 17);
deviceToConnectTo = myBluetoothAdapter.getRemoteDevice(address);
connectToDevice(deviceToConnectTo);
}
});
}
And here is my connectToDevice() void:
public void connectToDevice(BluetoothDevice device){
try {
mmSocket = device.createRfcommSocketToServiceRecord(MY_UUID);
myBluetoothAdapter.cancelDiscovery();
} catch (IOException e){}
try{
mmSocket.connect();
} catch (IOException e){
showMsg("Error Connecting to device");
try{
mmSocket.close();
} catch (IOException exception){}
}
}
showMsg is basically a Toast.makeText, it keeps giving me "
Error Connecting to device
toast message, which means that somehow it was impossible to connect.
Can someone tell me why?
I'm using API level 10 and trying to connect to HC-05 Bluetooth Module.
Ok, it seems I managed to fix the problem of not connecting to the HC-05 Bluetooth module. The problem was the UUID I was using.
I changed the UUID to:
private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
It's used to bluetooth serial boards such as HC-05.

Internet Connectivity Listener in Xamarin.Forms

I am new in Xamarin.Forms and I want to check internet connectivity status in iOS and Android app. In fact using CrossConnectivity Plugins I am able to check internet connectivity successfully but It is not working as Listener. For example, When I open my app and internet connection is not there then it shows me message that "No internet connection" and now if I ON my mobile data then also it shows me same message. I am using below code for this:
string isConnected=CrossConnectivity.Current.IsConnected?"Connected":"No Connection";
My app is not able to listen the changing status of internet connectivity in middle something.
Using the plugin CrossConnectivity, you need to listen to changes via the event ConnectivityChanged, so in your page, or your App class, add this code to write an event handler:
CrossConnectivity.Current.ConnectivityChanged += (sender, args) =>
{
//your implementation
this.DisplayAlert("Connectivity Changed", "IsConnected: " + args.IsConnected.ToString(), "OK");
};
I have the solution for Android but i haven't started working on ios part
(better than nothing ;)
First Create a broadcastReceiver
public class Localize: BroadcastReceiver
{
public static Context context;
public Localize(Context ctx)
{
context = ctx;
}
public override void OnReceive (Context context, Intent intent)
{
isNetworkAvailable (context);
}
public void isNetworkAvailable(Context context)
{
Boolean state = false;
ConnectivityManager connectivity = (ConnectivityManager)
context.GetSystemService(Context.ConnectivityService);
if (connectivity != null)
{
NetworkInfo[] info = connectivity.GetAllNetworkInfo();
foreach (NetworkInfo nwork in info)
{
if (nwork.GetState () == NetworkInfo.State.Connected) {
ConnectionDetected();//Execute your fonction here
break;
}
}
}
}
Then register your broadcastreceiver with intent in your activity (in MainActivity for example)
IntentFilter filter = new IntentFilter(ConnectivityManager.ConnectivityAction);
receiver = new Localize(this);
RegisterReceiver(receiver, filter);
This should work as long as your application is running.. If you want a service that runs even if your App is killed you should create a service and then register broadcastReceiver in your service..
CrossConnectivity.Current.IsReachable("localhost");
this also works if you download package. I haven't tested it thoroughly

Synchronizing an audio file over network in Unet

I have a gameObject "plane" that isn't controlled by the clients. it gets spawned with an audio source that plays a clip when the host clicks a certain button. i would like the sound to be heard by the clients, i tried using rpc but i can't seem to be able to send them.
i keep getting the error: Found no behaviour for incoming [ClientRpc:InvokeRpcRpc_SendSoundIDToServer] on plane (UnityEngine.GameObject), the server and client should have the same NetworkBehaviour instances.
It's been driving me crazy for more than a day, i would really apreciate some help.
Here's my code:
using UnityEngine;
using UnityEngine.Networking;
[RequireComponent(typeof(AudioSource))]
[RequireComponent(typeof(NetworkIdentity))]
public class SpoolUp : NetworkBehaviour
{
private AudioSource source;
public AudioClip[] clips;
public bool start;
void Start()
{
clips = Resources.LoadAll("Audio");
source = GetComponent();
source.playOnAwake = false;
}
public void Spool()
{
start = true;
if (isServer)
PlaySound(0);
}
public void PlaySound(int id)
{
if (id >= 0 && id < clips.Length)
{
RpcPlaySound(id);
}
}
[ClientRpc]
void RpcPlaySound(int id)
{
source.PlayOneShot(clips[id]);
}
PS: I also get the following warning: ClientRpc [ClientRpc:InvokeRpcRpcPlaySound] handler not found [netId=4]

MVC CQRS App - making it so remote workers can work with no fuss

I got my ting set up with NSB, and MVC3, RAvenDb and common domain etc -works like a charm
Now - the MVC layer only pushes commands to the NSB and reads from the readmodel directly using the DocumentSession provided by RavenDb
My question is - I don't want the UI devs to have to configure and fire a raven console server and the read and write servers with NSB
How do other people handle this?
I want the MVC app to be fire-able without any of that.
What do you do?
We use a simple wrapper around NSB specifics, similar to what is being suggested. You don't have to use full IOC, but you can at least use a Factory. Here is the interface definition(I can follow up with the NSB implementation if you so require):
public interface IServiceBusAgent<T>
{
void Send(Action<T> messageConstructor);
void Send(String destination, Action<T> messageConstructor);
void Send(String destination, String correlationId, Action<T> messageConstructor);
void SendLocal(Action<T> messageConstructor);
}
public class NServiceBusAgent<T> : IServiceBusAgent<T> where T : IMessage
{
private readonly IBus bus;
public NServiceBusAgent() : this(null) { }
public NServiceBusAgent(IBus bus)
{
this.bus = bus;
}
public void Send(Action<T> messageConstructor)
{
if (null != messageConstructor)
this.bus.Send<T>(messageConstructor);
}
public void Send(String destination, Action<T> messageConstructor)
{
Send(destination, String.Empty, messageConstructor);
}
public void Send(String destination, String correlationId, Action<T> messageConstructor)
{
if (String.IsNullOrEmpty(destination))
throw new ArgumentNullException("destination");
if (null != messageConstructor)
this.bus.Send<T>(destination, correlationId, messageConstructor);
}
public void SendLocal(Action<T> messageConstructor)
{
if (null != messageConstructor)
this.bus.SendLocal<T>(messageConstructor);
}
}
We communicate with the "backend" from our webservice via interfaces.
When starting up the web we use the IOCC/DI Pattern to use real or dev mode instances of that interface.
For example your "OrderCommandApplication" that would contain commands to create orders would have an interface IOrderCommandApplication. now depending on the developer who starts the web we inject either the DemoOrderCommandApplication which only persists state in memory or the OrderCommandApplication which uses ravendb/wcf whatever.
Look at for example StructureMap or for some basics search for Inversion of Control Containers and the Dependency Injection pattern.

j2me bluetooth client. Function startInquiry nothing found

I develop simple j2me bluetooth client and have problem with bluetooth device search.
Function startInquiry nothing found.
Client : nokia 5220
Server : my pc with bluetooth adapter
All bluetooth devices is on.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.microedition.midlet.*;
import javax.bluetooth.*;
import java.util.Vector;
import javax.microedition.lcdui.*;
/**
* #author Администратор
*/
public class Midlet extends MIDlet implements DiscoveryListener
{
private static Vector vecDevices=new Vector();
private static String connectionURL=null;
private LocalDevice localDevice;
private DiscoveryAgent agent;
private RemoteDevice remoteDevice;
private RemoteDevice[] devList;
private Display display;
private Form form;
public void startApp() {
display = Display.getDisplay(this);
form = new Form( "Client" );
try {
localDevice = LocalDevice.getLocalDevice();
} catch( BluetoothStateException e ) {
e.printStackTrace();
}
form.append("Address: "+localDevice.getBluetoothAddress()+"\n\n");
form.append("Name: "+localDevice.getFriendlyName()+"\n\n");
try {
agent = localDevice.getLocalDevice().getDiscoveryAgent();
form.append("Starting device inquiry... \n\n");
boolean si = agent.startInquiry(DiscoveryAgent.GIAC, this);
if ( si ) {
form.append("true");
} else {
form.append("false");
}
} catch( BluetoothStateException e ) {
}
int deviceCount = vecDevices.size();
if(deviceCount <= 0){
form.append("No Devices Found .");
}
else{
//print bluetooth device addresses and names in the format [ No. address (name) ]
form.append("Bluetooth Devices: ");
for (int i = 0; i < deviceCount; i++) {
remoteDevice=(RemoteDevice)vecDevices.elementAt(i);
form.append( remoteDevice.getBluetoothAddress() );
}
}
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
//add the device to the vector
if(!vecDevices.contains(btDevice)){
vecDevices.addElement(btDevice);
}
}
public void inquiryCompleted(int discType)
{
}
//implement this method since services are not being discovered
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
if(servRecord!=null && servRecord.length>0){
connectionURL=servRecord[0].getConnectionURL(0,false);
}
}
//implement this method since services are not being discovered
public void serviceSearchCompleted(int transID, int respCode) {
}
}
Not sure what the exact problem is, but you definitely don't want to be doing this in your midlet's startApp() method. This is a system lifecycle method, and should return quickly, but scanning for bluetooth devices will block it for a long time. Your startApp() method is tying up the device's resources which it could need for doing the actual scanning!
Refactor, so your device scanning is done in a new thread, then see what happens.
You seem to have misunderstood how the Bluetooth API works. The startInquiry method only starts the device discovery process and returns immediately afterwards, leaving the discovery running in the background. When devices are discovered, you get a callback of the deviceDiscovered method for each of them, and when the discovery process has completed, you get a callback of the inquiryCompleted method. So you need to move the accessing of the vecDevices member and the form manipulation from startApp to inquiryCompleted to be able to actually show the discovered information.
You say all devices are on - but also check if all devices are discoverable.
I've made this mistake before myself!
Lookup the method LocalDevice.setDiscoverable() if you want to toggle between modes programatically.

Resources