func (c *OnvifClient) GetSystemDateAndTime() (string, error) {
	datetime, err := c.onvifDevice.Device.GetSystemDateAndTime()
	if err != nil {
		return "", err
	}
	datetimeJSON, err := json.Marshal(datetime)
	if err != nil {
		return "", err
	}
	return string(datetimeJSON), nil
}
GetSystemDateAndTime returns the current date and time as reported by the ONVIF GetSystemDateAndTime command
package driver
import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"time"
	"github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger"
	"github.com/faceterteam/onvif4go"
	"github.com/faceterteam/onvif4go/device"
	"github.com/faceterteam/onvif4go/onvif"
	"github.com/edgexfoundry/device-camera-go/internal/pkg/digest"
)
type OnvifClient struct {
	ipAddress    string
	user         string
	password     string
	cameraAuth   string
	onvifDevice  *onvif4go.OnvifDevice
	lc           logger.LoggingClient
	digestClient digest.Client
}
func NewOnvifClient(ipAddress string, user string, password string, cameraAuth string, lc logger.LoggingClient) *OnvifClient {
	c := OnvifClient{
		ipAddress:  ipAddress,
		user:       user,
		password:   password,
		cameraAuth: cameraAuth,
		lc:         lc,
	}
	dev := onvif4go.NewOnvifDevice(c.ipAddress)
	switch cameraAuth {
	case BASIC_AUTH, DIGEST_AUTH:
		dev.Auth(user, password)
	case NO_AUTH:
	default:
		lc.Errorf("unsupported AuthMethod: %s", cameraAuth)
		return nil
	}
	err := dev.Initialize()
	if err != nil {
		lc.Error(fmt.Sprintf("Error initializing ONVIF Client: %v", err.Error()))
		return nil
	}
	c.onvifDevice = dev
	c.digestClient = digest.NewDClient(&http.Client{}, user, password)
	return &c
}
func (c *OnvifClient) GetDeviceInformation() (string, error) {
	info, err := c.onvifDevice.Device.GetDeviceInformation()
	if err != nil {
		return "", err
	}
	deviceInfo, err := json.Marshal(info)
	if err != nil {
		return "", err
	}
	return string(deviceInfo), nil
}
func (c *OnvifClient) GetProfileInformation() (string, error) {
	profiles, err := c.onvifDevice.Media.GetProfiles()
	if err != nil {
		return "", err
	}
	mediaProfiles, err := json.Marshal(profiles)
	if err != nil {
		return "", err
	}
	return string(mediaProfiles), nil
}
func (c *OnvifClient) GetStreamURI() (string, error) {
	profilesResp, err := c.onvifDevice.Media.GetProfiles()
	if err != nil {
		return "", err
	}
	if len(profilesResp.Profiles) == 0 {
		return "", fmt.Errorf("no onvif profiles found")
	}
	token := profilesResp.Profiles[0].Token
	uriResp, err := c.onvifDevice.Media.GetStreamURI(string(token), "RTP-Unicast", "RTSP")
	if err != nil {
		return "", fmt.Errorf("GetStreamURI failed: %v", err.Error())
	}
	uriJSON, err := json.Marshal(uriResp)
	if err != nil {
		return "", fmt.Errorf("error marshaling stream URI to json: %v", err.Error())
	}
	return string(uriJSON), nil
}
func (c *OnvifClient) GetSnapshot() ([]byte, error) {
	profilesResp, err := c.onvifDevice.Media.GetProfiles()
	if err != nil {
		return nil, err
	}
	if len(profilesResp.Profiles) == 0 {
		return nil, fmt.Errorf("no onvif profiles found")
	}
	token := profilesResp.Profiles[0].Token
	uriResponse, err := c.onvifDevice.Media.GetSnapshotURI(string(token))
	if err != nil {
		return nil, err
	}
	url := uriResponse.MediaUri.Uri
	req, err := http.NewRequest(http.MethodGet, string(url), nil)
	if err != nil {
		return nil, err
	}
	var resp *http.Response
	if c.cameraAuth == DIGEST_AUTH {
		resp, err = c.digestClient.Do(req)
	} else if c.cameraAuth == BASIC_AUTH {
		req.SetBasicAuth(c.user, c.password)
		httpClient := http.Client{}
		resp, err = httpClient.Do(req)
	} else {
		httpClient := http.Client{}
		resp, err = httpClient.Do(req)
	}
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("http request for image failed with status %v", resp.StatusCode)
	}
	buf, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("error reading http request: %v", err)
	}
	return buf, nil
}