HOWTO setup wifi capable PI device (running ubuntu/armbiain or similar) for wifi capable IoTs

This is a simple howto for people who are setting up an IoT device with WiFi connectivity ( ie emontx with esp module ) on a cheap orange Pi pc plus that is wifi capable. I have all my IoT devices communicating directly to my orange Pi. I originally had it going through my router, but with thousands of requests per minute from several IoT devices at once, it would impact the performance of the router - so I removed the router from the equation. In the end it works much better and smoother with fewer lost packets, and I have the IoT device connecting to the unit from a couple of hundred meters away. It also isolates my IoT from direct access to the network, reducing the possibility of hacking my units externally.

installed – hostapd and dsnmasq

modify to your preferences

/etc/network/interface

# Local loopback
auto lo eth0 wlan0
iface lo inet loopback

# Wired adapter #1
allow-hotplug eth0
#no-auto-down eth0
iface eth0 inet dhcp
#	hwaddress ether # if you want to set MAC manually
#	pre-up /sbin/ifconfig eth0 mtu 3838 # setting MTU for DHCP, static just: mtu 3838

# Wired adapter #2
#allow-hotplug eth1
#iface eth1 inet dhcp
#	hwaddress ether # if you want to set MAC manually
#	pre-up /sbin/ifconfig eth0 mtu 3838 # setting MTU for DHCP, static just: mtu 3838

# Wireless adapter #1
iface wlan0 inet static
hostapd /etc/hostapd.conf
address 192.168.50.1
netmask 255.255.255.0
broadcast 255.255.255.255
network 192.168.50.0

#	wpa-ssid SSID
#	wpa-psk xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# to generate proper encrypted key: wpa_passphrase yourSSID yourpassword

/etc/hostapd.conf

interface=wlan0

ssid=IOT
channel=1

/etc/networkmanager/networkmanager.conf

[main]
dns=dnsmasq
plugins=ifupdown,keyfile

[ifupdown]
managed=true
[keyfile]
unmanaged-devices=interface-name:p2p0
unmanaged-devices=interface-name:wlan0

/etc/dnsmasq.conf ( added these lines)

interface=lo,wlan0
no-dhcp-interface=lo
dhcp-range=192.168.50.20,192.168.50.254,255.255.255.0,12h

/etc/sysctl.conf (added this line )

net.ipv4.ip_forward=1

/etc/rc.local ( added this line)

iptables -t nat -A POSTROUTING -s 192.168.50.0/24 ! -d 192.168.50.0/24  -j MASQUERADE

I hope this helps someone set up their project a bit easier than searching multiple websites for the info.