Class: Foscam::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/foscam/client.rb

Overview

TODO: put in some documentation for this class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Client

Returns a new instance of Client.



22
23
24
25
26
27
# File 'lib/foscam/client.rb', line 22

def initialize(args = {})
	@url = args.delete(:url)
	@username = args.delete(:username)
	@password = args.delete(:password)
	connect(@url, @username, @password)
end

Instance Attribute Details

#connectionFaraday

Returns The HTTP connection object to the camera.

Returns:

  • (Faraday)

    The HTTP connection object to the camera



20
21
22
# File 'lib/foscam/client.rb', line 20

def connection
  @connection
end

#passwordString

Returns The password for authentication to the camera.

Returns:

  • (String)

    The password for authentication to the camera



16
17
18
# File 'lib/foscam/client.rb', line 16

def password
  @password
end

#urlString

Returns the url to the camera.

Returns:

  • (String)

    the url to the camera



10
11
12
# File 'lib/foscam/client.rb', line 10

def url
  @url
end

#usernameString

Returns The username for authentication to the camera.

Returns:

  • (String)

    The username for authentication to the camera



13
14
15
# File 'lib/foscam/client.rb', line 13

def username
  @username
end

Instance Method Details

#camera_control(params) ⇒ FalseClass, TrueClass

Sets the camera sensor parameters

Parameters:

  • params (Hash)

    Parameters to set

Options Hash (params):

  • :resolution (Symbol, String)

    Set to one of the keys or values in CAMERA_PARAMS_RESOLUTION

  • :brightness (Fixnum)

    Value between 0 and 255

  • :contrast (Fixnum)

    Value between 0 and 6

  • :mode (Symbol, Integer)

    Value between 0 and 2 or option in CAMERA_CONTROL_MODE

  • :flip (Symbol, Integer)

    Value between 0 and 3 or option in CAMERA_CONTROL_ORIENTATION

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.

See Also:



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/foscam/client.rb', line 133

def camera_control(params)
	params.all? do |key, value|
		# validation
		case key
		when :resolution
			case value
			when Integer
				throw "invalid parameter value" unless [8,32].include?(value)
			when String || Symbol
				throw "invalid parameter value" unless ["vga","qvga"].include?(value.to_s.downcase)
				if value.to_s.downcase == "vga"
					value = 32
				elsif value.to_s.downcase == "qvga"
					value = 8
				end
			else
				throw "invalid parameter value type"
			end	
		when :brightness
			throw "invalid parameter value" if value.to_i < 0 || value.to_i > 255
		when :contrast
			throw "invalid parameter value" if value.to_i < 0 || value.to_i > 6
		when :mode
			case value
			when Integer
				throw "invalid parameter value" if value.to_i < 0 || value.to_i > 2
			when Symbol || String
				throw "invalid parameter value" unless CAMERA_CONTROL_MODE.keys.include?(value.to_s.downcase.to_sym)
				value = CAMERA_CONTROL_MODE[value.to_s.downcase.to_sym]
			else
				throw "invalid parameter value type"
			end
		when :flip
			case value
			when Integer
				throw "invalid parameter value" if value.to_i < 0 || value.to_i > 3
			when String || Symbol
				throw "invalid parameter value" unless CAMERA_CONTROL_ORIENTATION.keys.include?(value.to_s.downcase.to_sym)
				value = CAMERA_CONTROL_ORIENTATION[value.to_s.downcase.to_sym]
			else
				throw "invalid parameter value type"
			end
		else
			throw "invalid parameter"
		end
			
		response = @connection.get("camera_control.cgi?param=#{CAMERA_CONTROLS[key.to_sym]}&value=#{value}")
		response.success?
	end
end

#comm_write(params) ⇒ FalseClass, TrueClass

Write to comm

Parameters:

  • params (Hash)

Options Hash (params):

  • :baud (Fixnum)
  • :bytes (String)
  • :data (String)
  • :port (Fixnum)

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



541
542
543
544
# File 'lib/foscam/client.rb', line 541

def comm_write(params)
	response = @connection.get("comm_write.cgi?#{params.to_query}")
	response.success?
end

#connect(url, username = nil, password = nil) ⇒ Object

Connects to the foscam webcam

Examples:

connect to a camera

client = Foscam::Client.new
client.connect('http://192.168.0.1', 'foobar', 'secret')

Parameters:

  • url (String)

    The address to your camera

  • username (String) (defaults to: nil)

    username to authorize with the camera

  • password (String) (defaults to: nil)

    password to authorize with the camera



37
38
39
40
41
42
43
# File 'lib/foscam/client.rb', line 37

def connect(url, username = nil, password = nil)
	@url = url
	@username = username
	@password = password
	@connection = Faraday.new( :url => @url) unless @url.nil?
	@connection.basic_auth(@username, @password) unless @username.nil? && @password.nil?
end

#decoder_control(action) ⇒ FalseClass, TrueClass

Controls the pan and tilt of the camera

Parameters:

  • action (Symbol)

    A symbol corresponding to the desired action.

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.

See Also:



110
111
112
113
114
115
116
117
118
119
# File 'lib/foscam/client.rb', line 110

def decoder_control(action)
	case action
		when Symbol || String
			action_id = DECODER_CONTROLS[action.to_sym]
		else
			action_id = action
	end
	response = @connection.get("decoder_control.cgi?command=#{action_id}")
	response.success?
end

#get_camera_paramsHash

Obtains the cameras parameters (orientation, resolution, contrast, brightness)

Returns:

  • (Hash)

    The cameras parameters

    • :flip (String) The camera orientation.

    • :mode (String) The camera mode.

    • :resolution (String) The camera resolution.

    • :brightness (Fixnum) The camera brightness.

    • :contrast (Fixnum) The camera contrast.

See Also:



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/foscam/client.rb', line 93

def get_camera_params
	response = @connection.get('get_camera_params.cgi')
	response = response.success? ? parse_response(response) : {}
	unless response.empty?
		response[:flip] = CAMERA_PARAMS_ORIENTATION[response[:flip].to_i]
		response[:mode] = CAMERA_PARAMS_MODE[response[:mode].to_i]
		response[:resolution] = CAMERA_PARAMS_RESOLUTION[response[:resolution].to_i]
		[:brightness, :contrast].each {|field| response[field] = response[field].to_i}
	end
	response
end

#get_forbiddenSchedule::Week?

Returns the forbidden schedule for the camera

Returns:

  • (Schedule::Week, nil)

    If the request is unsuccessful then nil is returned.



566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# File 'lib/foscam/client.rb', line 566

def get_forbidden
	response = @connection.get("get_forbidden.cgi")
	params = response.success? ? parse_response(response) : {}
	schedule = {}
	unless params.empty?
		params.keys.each do |field|
			match = field.to_s.match(/schedule_(.+)_(\d)/)
			unless match.nil?
				schedule.merge!("#{match[1]}_#{match[2]}".to_sym => params[field].to_i)
			end
		end
		::Foscam::Schedule::Week.new(schedule)
	else
		nil
	end
end

#get_miscHash

Get miscellaneous parameters

Returns:

  • (Hash)

    If the request is unsuccessful the hash will be empty. Otherwise it contains the following fields:

    • :led_mode (Fixnum)

    • :ptz_auto_patrol_interval (Fixnum)

    • :ptz_auto_patrol_type (Fixnum)

    • :ptz_patrol_down_rate (Fixnum)

    • :ptz_patrol_h_rounds (Fixnum)

    • :ptz_patrol_left_rate (Fixnum)

    • :ptz_patrol_rate (Fixnum)

    • :ptz_patrol_right_rate (Fixnum)

    • :ptz_patrol_up_rate (Fixnum)

    • :ptz_patrol_v_rounds (Fixnum)

    • :ptz_preset_onstart (FalseClass,TrueClass)

    • :ptz_center_onstart (FalseClass,TrueClass)

    • :ptz_disable_preset (FalseClass,TrueClass)



634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'lib/foscam/client.rb', line 634

def get_misc
	response = @connection.get("get_misc.cgi")
	response = response.success? ? parse_response(response) : {}
	unless response.empty?
		[:ptz_disable_preset, :ptz_preset_onstart, :ptz_center_onstart].each do |field|
			response[field] = response[field].to_i > 0
		end
		[:ptz_auto_patrol_interval, :ptz_patrol_h_rounds, :ptz_patrol_v_rounds, :ptz_patrol_rate, :ptz_patrol_up_rate, :ptz_patrol_down_rate, :ptz_patrol_left_rate, :ptz_patrol_right_rate].each do |field|
			response[field] = response[field].to_i
		end
		response[:led_mode] = LED_MODE[response[:led_mode].to_i]
		response[:ptz_auto_patrol_type] = PTZ_AUTO_PATROL_TYPE[response[:ptz_auto_patrol_type].to_i]
		response
	end
	response
end

#get_paramsHash

Returns all the parameters for the camera

Returns:

  • (Hash)

    If the request is unsuccessful the hash will be empty. Otherwise it contains the following fields:

    • :id (String) The device id.

    • :sys_ver (String) Firmware version number.

    • :app_ver (String) Web UI version number.

    • :alias (String) The assigned camera name.

    • :now (DateTime) The camera’s time.

    • :tz (String) The camera time zone.

    • :ntp_enable (FalseClass, TrueClass) Whether the ntp server is enabled.

    • :ntp_svr (String) Address to the ntp server.

    • :user1_name (String) Username of user1.

    • :user1_pwd (String) Password of user1.

    • :user1_pri (String) Privilages of user1.

    • :user8_name (String) Username of user8.

    • :user8_pwd (String) Password of user8.

    • :user8_pri (String) Privilages of user8.

    • :dev2_alias (String) The 2nd Device alias

    • :dev2_host (String) The 2nd Device host(IP or Domain name)

    • :dev2_port (String) The 2nd Device port.

    • :dev2_user (String) The 2nd Device user name .

    • :dev2_pwd (String) The 2nd Device password.

    • :dev9_alias (String) The 9th Device alias

    • :dev9_host (String) The 9th Device host(IP or Domain name)

    • :dev9_port (Fixnum) The 9th Device port.

    • :dev9_user (String) The 9th Device user name .

    • :dev9_pwd (String) The 9th Device password.

    • :ip_address (String) The network ip address of the camera.

    • :mask (String) The network mask of the camera.

    • :gateway (String) The network gateway of the camera.

    • :dns (String) The address of the dns server.

    • :port (Fixnum) The network port.

    • :wifi_enable (FalseClass, TrueClass) Whether wifi is enabled or not.

    • :wifi_ssid (String) Your WIFI SSID

    • :wifi_encrypt (FalseClass, TrueClass) Whether wifi is encrypted or not.

    • :wifi_defkey (String) Wep Default TX Key

    • :wifi_key1 (String) Key1

    • :wifi_key2 (String) Key2

    • :wifi_key3 (String) Key3

    • :wifi_key4 (String) Key4

    • :wifi_autht (String) ype The Authetication type 0:open 1:share

    • :wifi_keyfo (String) rmat Keyformat 0:Hex 1:ASCII

    • :wifi_key1_bits (String) 0:64 bits; 1:128 bits

    • :wifi_key2_bits (String) 0:64 bits; 1:128 bits

    • :wifi_key3_bits (String) 0:64 bits; 1:128 bits

    • :wifi_key4_bits (String) 0:64 bits; 1:128 bits

    • :wifi_channel (String) Channel (default 6)

    • :wifi_mode (String) Mode (default 0)

    • :wifi_wpa_psk (String) wpa_psk

    • :pppoe_enable (FalseClass, TrueClass)

    • :pppoe_user (String)

    • :pppoe_pwd (String)

    • :upnp_enable (FalseClass, TrueClass)

    • :ddns_service (String)

    • :ddns_user (String)

    • :ddns_pwd (String)

    • :ddns_host (String)

    • :ddns_proxy_svr (String)

    • :ddns_proxy_port (Fixnum)

    • :mail_svr (String)

    • :mail_port (Fixnum)

    • :mail_tls (String)

    • :mail_user (String)

    • :mail_pwd (String)

    • :mail_sender (String)

    • :mail_receiver1 (String)

    • :mail_receiver2 (String)

    • :mail_receiver3 (String)

    • :mail_receiver4 (String)

    • :mail_inet_ip (String)

    • :ftp_svr (String)

    • :ftp_port (String)

    • :ftp_user (String)

    • :ftp_pwd (String)

    • :ftp_dir (String)

    • :ftp_mode (String)

    • :ftp_upload_interval (String)

    • :ftp_filename (String)

    • :ftp_numberoffiles (Fixnum)

    • :ftp_schedule_enable (FalseClass, TrueClass)

    • :ftp_schedule (Schedule::Week)

    • :alarm_motion_armed (FalseClass, TrueClass)

    • :alarm_motion_sensitivity (Fixnum)

    • :alarm_motion_compensation (Fixnum)

    • :alarm_input_armed (FalseClass, TrueClass]

    • :alarm_ioin_level (Fixnum)

    • :alarm_iolinkage (Fixnum)

    • :alarm_preset (Fixnum)

    • :alarm_ioout_level (Fixnum)

    • :alarm_mail (FalseClass, TrueClass)

    • :alarm_upload_interval (Fixnum)

    • :alarm_http (FalseClass, TrueClass)

    • :alarm_msn (FalseClass, TrueClass)

    • :alarm_http_url (String)

    • :alarm_schedule_enable (FalseClass, TrueClass)

    • :alarm_schedule (Schedule::Week)

    • :decoder_baud (Fixnum)

    • :msn_user (String)

    • :msn_pwd (String)

    • :msn_friend1 (String)

    • :msn_friend2 (String)

    • :msn_friend3 (String)

    • :msn_friend4 (String)

    • :msn_friend5 (String)

    • :msn_friend6 (String)

    • :msn_friend7 (String)

    • :msn_friend8 (String)

    • :msn_friend9 (String)

    • :msn_friend10 (String)



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/foscam/client.rb', line 311

def get_params
	response = @connection.get("get_params.cgi")
	response = response.success? ? parse_response(response) : {}
	unless response.empty?
		alarm_schedule = {}
		ftp_schedule = {}
		response.keys.each do |field|
			ftp_match = field.to_s.match(/ftp_schedule_(.+)_(\d)/)
			unless ftp_match.nil?
				value = response.delete(field)
				ftp_schedule.merge!("#{ftp_match[1]}_#{ftp_match[2]}".to_sym => value.to_i)
			end

			alarm_match = field.to_s.match(/alarm_schedule_(.+)_(\d)/)
			unless alarm_match.nil?
				value = response.delete(field)
				alarm_schedule.merge!("#{alarm_match[1]}_#{alarm_match[2]}".to_sym => value.to_i)
			end
		end

		response[:ftp_schedule] = ::Foscam::Schedule::Week.new(ftp_schedule)

		response[:alarm_schedule] = ::Foscam::Schedule::Week.new(alarm_schedule)

		response[:now] = ::DateTime.strptime(response[:now],'%s')
		[:ntp_enable, :wifi_enable, :pppoe_enable, :upnp_enable, :alarm_schedule_enable, :ftp_schedule_enable].each do |field|
			response[field] = response[field].to_i > 0
		end

		[:daylight_savings_time, :ddns_proxy_port, :ftp_port, :mail_port, :port, :dev2_port, :dev3_port, :dev4_port, :dev5_port, :dev6_port, :dev7_port, :dev8_port, :dev9_port].each do |field|
			response[field] = response[field].to_i
		end
		[:user1_pri, :user2_pri, :user3_pri, :user4_pri, :user5_pri, :user6_pri, :user7_pri, :user8_pri].each do |key|
			response[key] = USER_PERMISSIONS[response[key].to_i]
		end	
	end
	response
end

#get_statusHash

Obtains the cameras status information

Returns:

  • (Hash)

    The cameras status

    • :now (DateTime) The current time on the camera

    • :alarm_status (String) Returns an Alarm status

    • :ddns_status (String) Returns an UPNP status

    • :upnp_status (String) Returns an DDNS status

See Also:



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/foscam/client.rb', line 69

def get_status
	response = @connection.get('get_status.cgi')
	response = response.success? ? parse_response(response) : {}
	unless response.empty?
		response[:ddns_status] = DDNS_STATUS[response[:ddns_status].to_i]
		response[:upnp_status] = UPNP_STATUS[response[:upnp_status].to_i]
		response[:alarm_status] = ALARM_STATUS[response[:alarm_status].to_i]
		response[:now] = ::DateTime.strptime(response[:now],'%s')
	end
	response
end

#rebootFalseClass, TrueClass

Reboots the camera

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



187
188
189
190
# File 'lib/foscam/client.rb', line 187

def reboot
	response = @connection.get("reboot.cgi")
	response.success?
end

#restore_factoryFalseClass, TrueClass

Restore settings to the factory defaults

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



195
196
197
198
# File 'lib/foscam/client.rb', line 195

def restore_factory
	response = @connection.get("restore_factory.cgi")
	response.success?
end

#set_alarm(params) ⇒ FalseClass, TrueClass

Set alarm parameters

Parameters:

  • params (Hash)

Options Hash (params):

  • :motion_armed (TrueClass, FalseClass)

    Whether the motion is enabled or disabled

  • :input_armed (TrueClass, FalseClass)

    Whether the motion is enabled or disabled

  • :mail (TrueClass, FalseClass)

    whether to send email on alarm

  • :iolinkage (TrueClass, FalseClass)

    whether to send email on alarm

  • :motion_sensitivity (Fixnum)
  • :upload_interval (Fixnum)

    in seconds

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



528
529
530
531
# File 'lib/foscam/client.rb', line 528

def set_alarm(params)
	response = @connection.get("set_alarm.cgi?#{params.to_query}")
	response.success?
end

#set_alias(name) ⇒ FalseClass, TrueClass

Set the name of the camera

Parameters:

  • name (String)

    The name of the camera which is 20 characters or less.

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



369
370
371
372
373
# File 'lib/foscam/client.rb', line 369

def set_alias(name)
	throw "invalid parameter value" if name.length > 20
	response = @connection.get("set_alias.cgi?alias=#{name}")
	response.success?
end

#set_datetime(params) ⇒ FalseClass, TrueClass

Set the datetime of the camera

Parameters:

  • params (Hash)

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



379
380
381
382
383
384
# File 'lib/foscam/client.rb', line 379

def set_datetime(params)
	# Extract the time zone
	throw "invalid parameter value" if params.has_key?(:ntp_svr) && params[:ntp_svr].length > 64
	response = @connection.get("set_datetime.cgi?#{params.to_query}")
	response.success?
end

#set_ddns(params) ⇒ FalseClass, TrueClass

Set the ddns parameters

Parameters:

  • params (Hash)

Options Hash (params):

  • :user (String)
  • :pwd (String)
  • :host (String)
  • :service (String)

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



472
473
474
475
476
477
478
# File 'lib/foscam/client.rb', line 472

def set_ddns(params)
	throw "invalid parameter value" if params.has_key?(:user) && params[:user].length > 20
	throw "invalid parameter value" if params.has_key?(:pwd) && params[:pwd].length > 20
	throw "invalid parameter value" if params.has_key?(:host) && params[:host].length > 40
	response = @connection.get("set_ddns.cgi?#{params.to_query}")
	response.success?
end

#set_decoder(baud) ⇒ FalseClass, TrueClass

Set decoder baud

Parameters:

  • baud (String, Symbol)

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



656
657
658
659
660
# File 'lib/foscam/client.rb', line 656

def set_decoder(baud)
	baud = DECODER_BAUD_ID[baud.to_sym] if baud.is_a?(String) || baud.is_a?(Symbol)
	response = @connection.get("set_decoder.cgi?baud=#{baud}")
	response.success?
end

#set_forbidden(week) ⇒ FalseClass, TrueClass

Set Forbidden

Parameters:

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/foscam/client.rb', line 550

def set_forbidden(week)
	if week.is_a?(Schedule::Week)
		params = {}
		week.to_param.each_pair do |key, value|
			params.merge!("schedule_#{key}" => value)
		end
		response = @connection.get("set_forbidden.cgi?#{params.to_query}")
		response.success?
	else
		false
	end
end

#set_ftp(params) ⇒ FalseClass, TrueClass

Set the ftp parameters

Parameters:

  • params (Hash)

Options Hash (params):

  • :dir (String)
  • :user (String)
  • :pwd (String)
  • :svr (String)
  • :port (Fixnum)
  • :upload_interval (Fixnum)

    in seconds

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



490
491
492
493
# File 'lib/foscam/client.rb', line 490

def set_ftp(params)
	response = @connection.get("set_ftp.cgi?#{params.to_query}")
	response.success?
end

#set_mail(params) ⇒ FalseClass, TrueClass

Set the smtp server mail notification parameters

Parameters:

  • params (Hash)

Options Hash (params):

  • :user (String)

    must be less than 20 characters

  • :pwd (String)

    must be less than 20 characters

  • :svr (String)
  • :port (Fixnum)
  • :sender (String)

    must be less than 40 characters

  • :receiver1 (String)

    must be less than 40 characters

  • :receiver2 (String)

    must be less than 40 characters

  • :receiver3 (String)

    must be less than 40 characters

  • :receiver4 (String)

    must be less than 40 characters

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



508
509
510
511
512
513
514
515
516
# File 'lib/foscam/client.rb', line 508

def set_mail(params)
	throw "invalid parameter value" if params.has_key?(:user) && params[:user].length > 20
	throw "invalid parameter value" if params.has_key?(:pwd) && params[:pwd].length > 20
	[:sender, :receiver1, :receiver2, :receiver3, :receiver4].each do |key|
		throw "invalid parameter value" if params.has_key?(key) && params[key].length > 40
	end
	response = @connection.get("set_mail.cgi?#{params.to_query}")
	response.success?
end

#set_misc(params) ⇒ FalseClass, TrueClass

Set miscellaneous parameters

Parameters:

  • params (Hash)

Options Hash (params):

  • :led_mode (Fixnum)
  • :ptz_auto_patrol_interval (Fixnum)
  • :ptz_auto_patrol_type (Fixnum)
  • :ptz_patrol_down_rate (Fixnum)
  • :ptz_patrol_h_rounds (Fixnum)
  • :ptz_patrol_left_rate (Fixnum)
  • :ptz_patrol_rate (Fixnum)
  • :ptz_patrol_right_rate (Fixnum)
  • :ptz_patrol_up_rate (Fixnum)
  • :ptz_patrol_v_rounds (Fixnum)
  • :ptz_preset_onstart (FalseClass, TrueClass)
  • :ptz_center_onstart (FalseClass, TrueClass)
  • :ptz_disable_preset (FalseClass, TrueClass)

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
# File 'lib/foscam/client.rb', line 600

def set_misc(params)
	url_params = params.clone
	[:ptz_patrol_rate, :ptz_patrol_up_rate, :ptz_patrol_down_rate, :ptz_patrol_left_rate, :ptz_patrol_right_rate].each do |key|
		throw "invalid parameter value" if (url_params.has_key?(key) && (url_params[key].to_i < 0 || url_params[key].to_i > 100))
	end
	[:ptz_auto_patrol_interval, :ptz_patrol_h_rounds, :ptz_patrol_v_rounds].each do |key|
		throw "invalid parameter value" if url_params.has_key?(key) && url_params[key].to_i < 0 
	end
	[:ptz_disable_preset, :ptz_preset_onstart, :ptz_center_onstart].each do |key|
		url_params[key] = handle_boolean(url_params[key]) if url_params.has_key?(key)
	end
	url_params[:led_mode] = LED_MODE_ID[url_params[:led_mode]] if url_params[:led_mode].is_a?(String) || url_params[:led_mode].is_a?(Symbol)
	url_params[:ptz_auto_patrol_type] = PTZ_AUTO_PATROL_TYPE_ID[url_params[:ptz_auto_patrol_type]] if url_params[:ptz_auto_patrol_type].is_a?(String) || url_params[:ptz_auto_patrol_type].is_a?(Symbol)
	response = @connection.get("set_misc.cgi?#{url_params.to_query}")
	response.success?
end

#set_network(params) ⇒ FalseClass, TrueClass

Set usernames, passwords and privilages

Parameters:

  • params (Hash)

Options Hash (params):

  • :ip (String)

    if ip set to “”,The device will DHCP Ip

  • :mask (String)

    mask

  • :gateway (String)

    gateway

  • :dns (String)

    dns server

  • :port (Fixnum)

    port number

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



423
424
425
426
# File 'lib/foscam/client.rb', line 423

def set_network(params)
	response = @connection.get("set_network.cgi?#{params.to_query}")
	response.success?
end

#set_pppoe(params) ⇒ FalseClass, TrueClass

Set the pppoe parameters

Parameters:

  • params (Hash)

Options Hash (params):

  • :enable (FalseClass, TrueClass)
  • :user (String)
  • :pwd (String)

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



447
448
449
450
451
452
# File 'lib/foscam/client.rb', line 447

def set_pppoe(params)
	throw "invalid parameter value" if params.has_key?(:user) && params[:user].length > 20
	throw "invalid parameter value" if params.has_key?(:pwd) && params[:pwd].length > 20
	response = @connection.get("set_pppoe.cgi?#{params.to_query}")
	response.success?
end

#set_upnp(flag) ⇒ FalseClass, TrueClass

Enable or disable upnp

Parameters:

  • flag (FalseClass, TrueClass)

    A boolean for whether to enable or disable upnp.

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



458
459
460
461
# File 'lib/foscam/client.rb', line 458

def set_upnp(flag)
	response = @connection.get("set_upnp.cgi?enable=#{handle_boolean(flag)}")
	response.success?
end

#set_users(params) ⇒ FalseClass, TrueClass

Set usernames, passwords and privilages

Parameters:

  • params (Hash)

Options Hash (params):

  • :user1 (String)

    Username of user1.

  • :pwd1 (String)

    Password of user1.

  • :pri1 (String)

    Privilages of user1.

  • ... (String)
  • :user8 (String)

    Username of user8.

  • :pwd8 (String)

    Password of user8.

  • :pri8 (String)

    Privilages of user8.

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



397
398
399
400
401
402
403
404
405
406
407
408
# File 'lib/foscam/client.rb', line 397

def set_users(params)
	[:user1, :pwd1, :user2, :pwd2, :user3, :pwd3, :user4, :pwd4, :user5, :pwd5, :user6, :pwd6, :user7, :pwd7, :user8, :pwd8].each do |key|
		throw "invalid parameter value" if params.has_key?(key) && params[key].length > 12
	end
	# if it is one of the matching symbols then set it to the corresponding integer
	[:pri1, :pri2, :pri3, :pri4, :pri5, :pri6, :pri7, :pri8].each do |key|
		params[key] = USER_PERMISSIONS_ID[key] if params.has_key?(key) && params[key].is_a?(Symbol)
	end

	response = @connection.get("set_users.cgi?#{params.to_query}")
	response.success?
end

#set_wifi(params) ⇒ FalseClass, TrueClass

Set the wifi parameters

Parameters:

  • params (Hash)

Options Hash (params):

  • :enable (FalseClass, TrueClass)

    Whether wifi is enabled or not.

  • :ssid (String)

    Your WIFI SSID

  • :encrypt (FalseClass, TrueClass)

    Whether wifi is encrypted or not.

  • :wpa_psk (String)

    wpa_psk

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



435
436
437
438
# File 'lib/foscam/client.rb', line 435

def set_wifi(params)
	response = @connection.get("set_wifi.cgi?#{params.to_query}")
	response.success?
end

#snapshotnil, ::MiniMagick::Image

Obtains a snapshot of the current image

Examples:

Save a captured image

client = Foscam::Client.new(url: 'http://192.168.0.1', username: 'foobar', password: 'secret')
image = client.snapshot
unless image.nil?
	image.write('image_filename.jpg')
end

Returns:

  • (nil, ::MiniMagick::Image)


54
55
56
57
# File 'lib/foscam/client.rb', line 54

def snapshot
	response = @connection.get('snapshot.cgi')
	response.success? ? ::MiniMagick::Image.read(response.body) : nil
end

#upgrade_firmwareFalseClass, TrueClass

Upgrade the camera firmware

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



353
354
355
# File 'lib/foscam/client.rb', line 353

def upgrade_firmware
	response = @connection.post("upgrade_firmware.cgi")
end

#upgrade_htmlsFalseClass, TrueClass

Upgrade the cameras html pages.

Returns:

  • (FalseClass, TrueClass)

    whether the request was successful.



360
361
362
# File 'lib/foscam/client.rb', line 360

def upgrade_htmls
	response = @connection.post("upgrade_htmls.cgi")
end