GithubHelp home page GithubHelp logo

smartlib's Introduction

SmartLib - A Onvif Library


SmartLib is useful for discovery IP cameras within networks which supports ONVIF and UPNP protocols.We can also add camera which supports these protocols.

Features

  • ONVIF & UPnP discovery
  • ONVIF device management (Services, device information, media profiles, raw media stream uri)
  • UPnP device information
  • Easily extendable with your custom requests

Discovery


The OnvifDiscovery class uses the Web Services Dynamic Discovery (WS-Discovery). This is a technical specification that defines a multicast discovery protocol to locate services on a local network. It operates over TCP and UDP port 3702 and uses IP multicast address 239.255.255.250. As the name suggests, the actual communication between nodes is done using web services standards, notably SOAP-over-UDP.

With WS-Discovery, the discovery tool puts SSDP queries on the network from its unicast address to 239.255.255.250 multicast address, sending them to the well-known UDP port 3702. The device receives the query, and answers to the discovery tool's unicast IP address from its unicast IP address. The reply contains information about the Web Services (WS) available on the device.

UPnP works in a very similar way, but on a different UDP port (1900). Compared to the WS-Discovery, the UPnP is intended for a general use (data sharing, communication, entertainment).

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());
    }
});

ONVIF


With the OnvifManager class it is possible to send requests to an ONVIF-supported device. All requests are sent asynchronously and you can use the OnvifResponseListener for errors and custom response handling. It is possible to create your own OnvifDevice or retrieve a list from the discover method in the DiscoveryManager

onvifManager = new OnvifManager();
onvifManager.setOnvifResponseListener(this);
OnvifDevice device = new OnvifDevice("192.168.0.4:36000", "admin", "admin");

Services

Returns information about services on the device.

onvifManager.getServices(device, new OnvifServicesListener() {
    @Override
    public void onServicesReceived(@Nonnull OnvifDevice onvifDevice, OnvifServices services) {
        
    }
});

Device information

Returns basic device information from the device. This includes the manufacturer, serial number, hardwareId, ...

onvifManager.getDeviceInformation(device, new OnvifDeviceInformationListener() {
    @Override
    public void onDeviceInformationReceived(@Nonnull OnvifDevice device, 
                                            @Nonnull OnvifDeviceInformation deviceInformation) {
        
    }
});

Media Profiles

Returns pre-configured or dynamically configured profiles. This command lists all configured profiles in a device. The client does not need to know the media profile in order to use the command.

onvifManager.getMediaProfiles(device, new OnvifMediaProfilesListener() {
    @Override
    public void onMediaProfilesReceived(@Nonnull OnvifDevice device, 
                                        @Nonnull List<OnvifMediaProfile> mediaProfiles) {
        
    }
});

Media Stream URI

Returns a raw media stream URI that remains valid indefinitely even if the profile is changed.

onvifManager.getMediaStreamURI(device, mediaProfiles.get(0), new OnvifMediaStreamURIListener() {
    @Override
    public void onMediaStreamURIReceived(@Nonnull OnvifDevice device, 
                                        @Nonnull OnvifMediaProfile profile, @Nonnull String uri) {
        
    }
});

PTZ

Send request for Pan,Tilt and Zoom.This provides rotating IP Camera to its Left,Right,Up and Down.also provides support for ZoomIn and ZoomOut.You have to provide PTZ Type like LEFT_MOVE,RIGHT_MOVE,UP_MOVE,DOWN_MOVE for rotating respectively.also ZOOM_IN and ZOOM_OUT for zooming.

onvifManager.sendPTZRequest(device, mediaProfile, PTZType.LEFT_MOVE, new OnvifPTZListener() {
                                           @Override
                                           public void onPTZReceived((@Nonnull OnvifDevice onvifDevice, boolean status) {
                                             //return PTZ status
    
    }
});

Stop PTZ

You can use stopPTZRequest for stopping rotation and zooming.

//for Stopping Pan,Tilt and Zoom
onvifManager.stopPTZRequest(device,mediaProfile);

Custom requests


It is possible to implement your custom ONVIF request by creating a new class and implementing the OnvifRequest interface and overriding the getXml() and getType() methods.

public class PTZRequest implements OnvifRequest {
    @Override
    public String getXml() {
        return "<GetServices xmlns=\"http://www.onvif.org/ver10/device/wsdl\">" +
                "<IncludeCapability>false</IncludeCapability>" +
                "</GetServices>";
    }
    @Override
    public OnvifType getType() {
        return OnvifType.CUSTOM;
    }
}

and send it to the appropriate OnvifDevice:

onvifManager.sendOnvifRequest(device, new PTZRequest());

Use the OnvifResponseListener to receive responses from your custom requests.

Download

Download the latest JAR or grab via Maven:

<dependency>
	<groupId>com.github.AjitSmartronThings</groupId>
	<artifactId>SmartLib</artifactId>
	<version>v1.0</version>
</dependency>

or Gradle:

implementation 'com.github.AjitSmartronThings:SmartLib:v1.0'

License

Copyright 2018 TThings - A Smartron Company.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

smartlib's People

Contributors

ajitsmartronthings avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.