Is there a way I can put NodeMCU in STATIONAP mode and communicate between two networks (the network which the esp8266 is the access point and the network which the esp8266 is the station)?
Thanks
Exactly the way that you mentioned does it. Use the commands below :
wifi.setmode(wifi.STATIONAP);
wifi.ap.config({ssid = YOUR_AP_NAME});
wifi.ap.setip({ip = DESIRED_AP_IP, netmask = DESIRED_AP_MASK, gateway = DESIRED_AP_GW});
wifi.sta.config(SSID, PASS);
wifi.sta.connect();
Related
If the broadcaster app (Android) and client app(IOS and Android) are connected to wifi in the same network, everything works fine. But when the broadcaster app is connected to mobile data connection, client app (IOS) shows black screen but the Android still works fine. I have searched some work around with this and they suggest to add STUN and TURN in my peerConnection , but i had already added before . Seems not working when the communication is stablished on different network connection. This is how i setup my RTCPeerConnection.
var rtcIceServers: [RTCIceServer] = []
rtcIceServers.append(RTCIceServer(urlStrings: [turnUrl], username:"*****",credential: "*********"))
rtcIceServers.append(RTCIceServer(urlStrings: [stunUrl]))
let rtcConf = RTCConfiguration()
rtcConf.iceServers = rtcIceServers
rtcConf.tcpCandidatePolicy = .disabled
rtcConf.bundlePolicy = RTCBundlePolicy.maxBundle
rtcConf.rtcpMuxPolicy = RTCRtcpMuxPolicy.require
rtcConf.continualGatheringPolicy = RTCContinualGatheringPolicy.gatherContinually
rtcConf.keyType = .ECDSA
let mediaConstraints = RTCMediaConstraints.init(mandatoryConstraints: mandatoryConstraints, optionalConstraints: nil)
let pc = self.peerConnectionFactory.peerConnection(with: rtcConf, constraints: mediaConstraints, delegate: self)
the client app requires only to receive video track , no audio added in the mandatory constraints. Thank you
After few days of debugging and comparing my setup to other sources, i resolved the issue by applying the right parameters to my RTCIceCandidate before i add to my peerConnection. I mistakenly applied candidate value to sdpMid parameter and id value to sdp parameter. Since everything works if both clients are in the same network connection, i never suspect my parameters, not until i understand quite a bit about why i need to use IceServers when clients are not in the same network. So RTCIceCandidate value is not quite important and also these ice servers when clients are in the same network thats why it was working even if RTCIceCandidate has wrong parameters applied. My bad...
RTCIceCandidate(sdp: id, sdpMLineIndex: label, sdpMid: candidate)// wrong
RTCIceCandidate(sdp: candidate, sdpMLineIndex: label, sdpMid: id)// correct
I need to get the device IP of the WiFi interface.
According to several StackOverflow threads, we could assume that "en0" corresponds to the Wi-Fi interface name :
https://stackoverflow.com/a/30754194/12866797
However, this feels like some kind of convention, not a standard.
Is there any consistent/standard way to retrieve the WiFi interface or the device WiFi IP address, using the iOS SDK ?
It would be nice if the API is available starting from iOS 11 but I won't be picky.
My best attempt was to use NWPathMonitor (iOS 12+) and monitor network changes corresponding to WiFi interfaces (NWInterface.InterfaceType.wifi) :
- (void) MonitorWifiInterface
{
m_pathMonitor = nw_path_monitor_create_with_type(nw_interface_type_wifi);
nw_path_monitor_set_update_handler(m_pathMonitor, ^(nw_path_t _Nonnull path) {
NSLog(#"[NetInterfaceUtilies] Network path changed");
nw_path_enumerate_interfaces(path, ^ bool (nw_interface_t _Nonnull itf)
{
NSLog(#"[NetInterfaceUtilies] Name : %s , Index : %u", nw_interface_get_name(itf), nw_interface_get_index(itf));
return true; // In order to continue the enumeration
});
});
nw_path_monitor_start(m_pathMonitor);
}
But I am not happy with it for the following reasons :
NWPathMonitor is supposed to be used for monitoring network changes : I haven't managed to get network information whenever I wanted, but only when WiFi has been set on/off.
I only managed to get the network interface name. But I can combine this data with the network interfaces retrieved with getifaddrs() in order to deduce the correct interface and IP : it's a step forward ?
It's "only" available starting from iOS 12.
I’m trying to get the IP address of the wifi interface on iOS devices using getifaddrs() and searching for the en0 name. This is working fine, but it assumes that en0 is always Wi-Fi. Is there some way to ensure that the interface I’m querying is specifically Wi-Fi for future proofing?
I use the following to find the wifi information by looking for a device which has a BSSID for the wifi station. It will also have a SSID.
The following class method returns the wifi info dictionary only. It is a simple extension to also return the device label (ifname variable). It is usually en0, as you have noted, but this would work as a way to make sure you pick up the wifi if it was not en0 in the future.
+ (NSDictionary *)getWifiInfo {
NSDictionary *ret=nil;
// Get the supported interfaces.
NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
// Find one with a BSSID and return that. This should be the wifi.
for (NSString *ifnam in ifs) {
NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
NSLog(#"Network device found = %#", info.description);
if (info[(__bridge NSString *)kCNNetworkInfoKeyBSSID]) {
// Return this as it should be the right one given it has a MAC address for the station
ret=info;
}
}
NSLog(#"Exit: returning wifi info = %#", ret.description);
return ret;
}
Once you have the device label based on BSSID, you can then use getifaddrs to get its IP, gateway etc knowing it is the wifi device.
NB This returns nil in the iOS simulator as there is no wifi detected, so for testing you need some workaround code to meet your needs.
A hacky option is to find the IP address with an associated MAC of 02:00:00:00:00:00. iOS hides the MAC address from coders and it has this value.
In my iOS application I am using libssh2 library. I am trying to ssh with ipv6 address, But socket is not creating and getting nil socket. It's working fine with ipv4 address.
static CFSocketRef _CreateSocketConnectedToHost(NSString* name, UInt16 port, CFOptionFlags callBackTypes, CFSocketCallBack callback, const CFSocketContext* context, CFTimeInterval timeOut)
I have search for this but not finding any result for ipv6 support with libssh2.
Please help me, Is libssh2 not supporting for ipv6? Can we make it working using libssh2?
just need to use ipv6 property in socket instead of ipv4 and you able to create socket with ipv6 address.
struct sockaddr_in6 ipAddress6;
CFSocketSignature signature;
ipAddress6.sin6_port = htons(port);
signature.protocolFamily = AF_INET6;
signature.protocol = IPPROTO_IP;//IPPROTO_IPV6;
signature.address = (CFDataRef)[NSData dataWithBytes:&ipAddress6 length:ipAddress6.sin6_len];
I would like to find out programmatically if the user is using a proxy in iOS. Is there a way to detect it with the new api's (ios 7 or 8)?
Also, Is it possible to find out if the user has proxy unknowingly?
you can simply find the proxy in the CFDictionaryRef response.
CFDictionaryRef dicRef = CFNetworkCopySystemProxySettings();
if proxy is enable then you can parse it like this.
const CFStringRef proxyCFstr = (const CFStringRef)CFDictionaryGetValue(dicRef,
(const void*)kCFNetworkProxiesHTTPProxy);
based on this you can make detect if proxy is enabled or not.
By default NSStream based sockets do not detect the System proxy settings, which is very inconvenient if you are trying to debug your NSStream based SSL traffic in Charles Proxy for example. To set the proxy setting for the streams I simply use:
NSInputStream *inStream;
NSOutputStream *outStream;
//...assign the streams...
NSDictionary *proxySettings = CFBridgingRelease(CFNetworkCopySystemProxySettings());
[inStream setProperty:proxySettings forKey:NSStreamSOCKSProxyConfigurationKey];
[outStream setProperty:proxySettings forKey:NSStreamSOCKSProxyConfigurationKey];