samtap / fang-hacks

Collection of modifications for the XiaoFang WiFi Camera
1.67k stars 340 forks source link

Static ip configuration not supported #86

Open samtap opened 7 years ago

samtap commented 7 years ago

Wifi Client mode is only available with DHCP. Multiple users have requested support for setting a static IP address, i.e. in #60, #61 and on discord.

The cloud app only supports dhcp and originally my scripts were developed to simply mimic cloudapp behaviour. Therefore no support for static ip configuration is available.

Users can setup a static dhcp lease in their router as interim solution.

A proper solution will be implemented in the next version

Tommy032017 commented 7 years ago

@samtap Thanks for your hints! I got it working and I could set a static IP instead DHCP by selecting "Client mode" in network. Switching back to cloud mode and DHCP is also working. At the moment it only works without setting permanent a gateway. You could add a gateway by an additional line with route add default gw IP-ADDRESS wlan0 , but after reboot gateway is lost again. I didn't find a solution to set the gateway permanent. However, I am happy with this and without gateway you could be sure, that the camera will not communicate outside to the internet. Of course NTP sync does not work, but I do not need a correct time stamp.

What I did: Change the the 01_network in /data/etc/scripts to: You have to edit this 2 entries in the 01_network and change the addresses according to your own network:

...
if [ $rc -eq 0 ]; then
ifconfig wlan0 192.168.150.97 netmask 255.255.255.0 broadcast 192.168.150.1 2>&1
         echo "nameserver 192.168.150.1" > /etc/resolv.conf 2>&1

         #udhcpc -i wlan0 -p /var/run/udhcpc.pid -b 2>&1

and

...
else
    echo "Failed to start wpa_supplicant"
    return 1
  fi
 ifconfig wlan0 192.168.150.97 netmask 255.255.255.0 broadcast 192.168.150.1 2>&1
      echo "nameserver 192.168.150.1" > /etc/resolv.conf 2>&1

      #udhcpc -i wlan0 -p /var/run/udhcpc.pid -b 2>&1

If you now click on "Wireless Client" the IP address will immediately changed to the new address (here 192.168.150.97). To go on and to "Apply" the setting permanent you have first renew the webpage to the new IP address: http://new_IP_address/cgi-bin/network (or ... status). Select again the "Wireless Client", select SSID and enter the "Passphrase" and now you are able to "Apply" the settings. To go back to DHCP, just select the wireless mode "Cloud" and "Apply".

image

josej69git commented 7 years ago

hi. how can i edit this file for static ip? access with ftp and telnet and not find 01_network in any directory. thanks for all.

samtap commented 7 years ago

It's 01-network in /media/mmcblk0p2/data/etc/scripts Please have a Linux machine/vm with sd reader so you can revert changes offline (ext2 filesystem, you can't read it on Windows), in case it doesn't work and locks you out!

Tommy032017 commented 7 years ago

@josej69git Works exactly like samtap described. Use an explorer with root privilege, p.e. "sudo nemo ". Edit the 01-network as described above, put back sd card to camera (camera always unplugged from power while changing the sd card) and don't forget to apply the "Wireless Client" mode twice.

josej69git commented 7 years ago

thanks, actually using windows, will probe it in al linux pc