Cannot connect to wpa2 enterprise using esp32 - wifi

I am trying to connect an esp32 device to the university wifi network which is a wpa2 enterprise.
Below is the code I have tried but I am unable to connect. It is from this link. The only changes I make to the code is adding my username (EAP_IDENTITY) and password. I am not sure if the university uses radius servers. I don't really understand the role of the test certificate so I don't make any changes to it.
Any help would be appreciated
#include <WiFi.h> //Wifi library
#include "esp_wpa2.h" //wpa2 library for connections to Enterprise networks
//Identity for user with password related to his realm (organization)
//Available option of anonymous identity for federation of RADIUS servers or 1st Domain RADIUS servers
//#define EAP_ANONYMOUS_IDENTITY "anonymous#tuke.sk" //anonymous#example.com, or you can use also nickname#example.com
#define EAP_IDENTITY "username#tuke.sk" //nickname#example.com, at some organizations should work nickname only without realm, but it is not recommended
#define EAP_PASSWORD "password" //password for eduroam account
//SSID NAME
const char* ssid = "eduroam"; // eduroam SSID
//Root CA cert (DigiCert Assured ID Root CA) in .pem format from:
//https://uvt.tuke.sk/wps/portal/uv/sluzby/bezdrotove-siete-wifi-na-tuke/prirucka-pouzivatela-bezdrotovej-siete-eduroam
const static char* test_root_ca PROGMEM = \
"-----BEGIN CERTIFICATE-----\n" \
"MIIDtzCCAp+gAwIBAgIQDOfg5RfYRv6P5WD8G/AwOTANBgkqhkiG9w0BAQUFADBl\n" \
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \
"d3cuZGlnaWNlcnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJv\n" \
"b3QgQ0EwHhcNMDYxMTEwMDAwMDAwWhcNMzExMTEwMDAwMDAwWjBlMQswCQYDVQQG\n" \
"EwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNl\n" \
"cnQuY29tMSQwIgYDVQQDExtEaWdpQ2VydCBBc3N1cmVkIElEIFJvb3QgQ0EwggEi\n" \
"MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtDhXO5EOAXLGH87dg+XESpa7c\n" \
"JpSIqvTO9SA5KFhgDPiA2qkVlTJhPLWxKISKityfCgyDF3qPkKyK53lTXDGEKvYP\n" \
"mDI2dsze3Tyoou9q+yHyUmHfnyDXH+Kx2f4YZNISW1/5WBg1vEfNoTb5a3/UsDg+\n" \
"wRvDjDPZ2C8Y/igPs6eD1sNuRMBhNZYW/lmci3Zt1/GiSw0r/wty2p5g0I6QNcZ4\n" \
"VYcgoc/lbQrISXwxmDNsIumH0DJaoroTghHtORedmTpyoeb6pNnVFzF1roV9Iq4/\n" \
"AUaG9ih5yLHa5FcXxH4cDrC0kqZWs72yl+2qp/C3xag/lRbQ/6GW6whfGHdPAgMB\n" \
"AAGjYzBhMA4GA1UdDwEB/wQEAwIBhjAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQW\n" \
"BBRF66Kv9JLLgjEtUYunpyGd823IDzAfBgNVHSMEGDAWgBRF66Kv9JLLgjEtUYun\n" \
"pyGd823IDzANBgkqhkiG9w0BAQUFAAOCAQEAog683+Lt8ONyc3pklL/3cmbYMuRC\n" \
"dWKuh+vy1dneVrOfzM4UKLkNl2BcEkxY5NM9g0lFWJc1aRqoR+pWxnmrEthngYTf\n" \
"fwk8lOa4JiwgvT2zKIn3X/8i4peEH+ll74fg38FnSbNd67IJKusm7Xi+fT8r87cm\n" \
"NW1fiQG2SVufAQWbqz0lwcy2f8Lxb4bG+mRo64EtlOtCt/qMHt1i8b5QZ7dsvfPx\n" \
"H2sMNgcWfzd8qVttevESRmCD1ycEvkvOl77DZypoEd+A5wwzZr8TDRRu838fYxAe\n" \
"+o0bJW1sj6W3YQGx0qMmoRBxna3iw/nDmVG3KwcIzi7mULKn+gpFL6Lw8g==\n" \
"-----END CERTIFICATE-----\n";
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.print(F("Connecting to network: "));
Serial.println(ssid);
WiFi.disconnect(true); //disconnect form wifi to set new wifi connection
WiFi.mode(WIFI_STA); //init wifi mode
esp_wifi_sta_wpa2_ent_set_ca_cert((uint8_t *)test_root_ca, strlen(test_root_ca) + 1);
//esp_wifi_sta_wpa2_ent_set_ca_cert((uint8_t *)test_root_ca, strlen(test_root_ca));
//esp_wifi_sta_wpa2_ent_set_identity((uint8_t *)EAP_ANONYMOUS_IDENTITY, strlen(EAP_ANONYMOUS_IDENTITY));
esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EAP_IDENTITY, strlen(EAP_IDENTITY));
esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EAP_PASSWORD, strlen(EAP_PASSWORD));
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT(); //set config settings to default
esp_wifi_sta_wpa2_ent_enable(&config); //set config settings to enable function
WiFi.begin(ssid); //connect to wifi
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.println("");
Serial.println(F("WiFi is connected!"));
Serial.println(F("IP address set: "));
Serial.println(WiFi.localIP()); //print LAN IP
}
void loop() {
}

Related

NET6.0 FTP server networking issue on Docker container

I’m developing a NET 6.0 FTP server as part of a functionality to load the firmware of a hardware device. I need to have it inside a Docker container but I’m unable to make it work on that environment when it works perfectly when I execute it as a regular executable. It seems to be something related to docker networking but I can’t figure it out what it is.
This is the Dockerfile for the container, that is based on Alpine (mcr.microsoft.com/dotnet/aspnet:6.0-alpine), with some additions from the default Dockerfile created by Visual Studio:
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
RUN apk add openrc --no-cache
ENV MUSL_LOCALE_DEPS cmake make musl-dev gcc gettext-dev libintl
ENV MUSL_LOCPATH /usr/share/i18n/locales/musl
RUN apk add --no-cache \
$MUSL_LOCALE_DEPS \
&& wget https://gitlab.com/rilian-la-te/musl-locales/-/archive/master/musl-locales-master.zip \
&& unzip musl-locales-master.zip \
&& cd musl-locales-master \
&& cmake -DLOCALE_PROFILE=OFF -D CMAKE_INSTALL_PREFIX:PATH=/usr . && make && make install \
&& cd .. && rm -r musl-locales-master
RUN apk add icu-libs
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
WORKDIR /src
COPY ["nuget.config", "."]
COPY ["CONTAINERS/Project1/Project1.csproj", "CONTAINERS/Project/"]
RUN dotnet restore "CONTAINERS/Project1.csproj"
COPY . .
WORKDIR "/src/CONTAINERS/Project1"
RUN dotnet build "Project1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Project1.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project1.dll"]
The Docker run parameters are these
-p 20:20 -p 21000-22000:21000-22000
where 20 is the control port for FTP, it is the port used by that external hardware device and cannot be modified by me, and 21000-22000 is the range for FTP passive mode.
The FTP server code is quite simple and it works nice directly being executed in the host machine:
public class FtpServer : IDisposable
{
...
public ErrorCode Start(string ip, int port, string basepath, string user, string password, int minPassivePort = 0, int maxPassivePort = 0)
{
ErrorCode retVal = ErrorCode.Success;
_basepath = basepath;
_user = user;
_password = password;
PassivePortMin = minPassivePort;
PassivePortMax = maxPassivePort;
ServicePointManager.DefaultConnectionLimit = 200;
_localEndPoint = new IPEndPoint(IPAddress.Parse(ip), port);
_listener = new TcpListener(_localEndPoint);
_listening = true;
_activeConnections = new List<ClientConnection>();
try
{
_listener.Start();
LocalEndpoint = ((IPEndPoint)_listener.LocalEndpoint).Address.ToString();
_listener.BeginAcceptTcpClient(HandleAcceptTcpClient, _listener);
}
catch (Exception ex)
{
log.Error("Error starting FTP server", ex);
retVal = ErrorCode.ConnectionFailure;
}
return retVal;
}
private void HandleAcceptTcpClient(IAsyncResult result)
{
if (_listening)
{
TcpClient client = _listener.EndAcceptTcpClient(result);
_listener.BeginAcceptTcpClient(HandleAcceptTcpClient, _listener);
ClientConnection connection = new ClientConnection(client, _user, _password, _basepath);
ThreadPool.QueueUserWorkItem(connection.HandleClient, client);
}
}
public class ClientConnection
{
public ClientConnection(TcpClient client, string username, string password, string basepath)
{
_controlClient = client;
_currentUser = new User
{
Username = username,
Password = password,
HomeDir = basepath
};
_validCommands = new List<string>();
}
public void HandleClient(object obj)
{
// bool error = false;
try
{
_remoteEndPoint = (IPEndPoint)_controlClient.Client.RemoteEndPoint;
_clientIP = _remoteEndPoint.Address.ToString();
_controlStream = _controlClient.GetStream();
_controlReader = new StreamReader(_controlStream);
_controlWriter = new StreamWriter(_controlStream);
_controlWriter.WriteLine("220 Service Ready.");
_controlWriter.Flush();
_validCommands.AddRange(new string[] { "AUTH", "USER", "PASS", "QUIT", "HELP", "NOOP" });
string line;
_dataClient = new TcpClient();
string renameFrom = null;
while ((line = _controlReader.ReadLine()) != null)
{
string response = null;
string[] command = line.Split(' ');
string cmd = command[0].ToUpperInvariant();
string arguments = command.Length > 1 ? line.Substring(command[0].Length + 1) : null;
if (arguments != null && arguments.Trim().Length == 0)
{
arguments = null;
}
if (!_validCommands.Contains(cmd))
{
response = CheckUser();
}
if (cmd != "RNTO")
{
renameFrom = null;
}
Console.WriteLine(cmd + " " + arguments);
if (response == null)
{
switch (cmd)
{
default:
response = "502 Command not implemented";
break;
}
}
if (_controlClient == null || !_controlClient.Connected)
{
break;
}
else
{
if (!string.IsNullOrEmpty(response))
{
_controlWriter.WriteLine(response);
_controlWriter.Flush();
}
Console.WriteLine(response);
if (response.StartsWith("221"))
{
break;
}
}
}
}
catch (Exception ex)
{
log.Error("Error sending command", ex);
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
Dispose();
}
}
The issue seems to be located in _controlWriter, it seems that anything is blocking the response to the device (220 Service Ready) or maybe the frame is not being redirected to the right network interface, because nothing is read from _controlReader. As I mentioned earlier, this exact same code works perfectly when I execute it in the host machine, outside Docker container, that's the reason why I think it could be something related to Docker networking.
I hope you can help me, thanks!
It was something related to carriage return. Since docker container used a Linux based image, the carriage return was \n and the device expected \r\n.
Thanks to everyone who took a look at this.

ESP8266 create another WiFiClientSecure always fail https request

I have some ESP8266 and ESP32.
I use them with a MQTT (SSL) server and a web server.
I use two WiFiClientSecure to avoid to be disconnected to my MQTT server.
One WiFiClientSecure instance is dedicate to the MQTT server and the other one to HTTPS requests
The ESP32 works well, I can connect to my MQTT server and send HTTPS request without issue.
The ESP8266 (Wemos d1 mini) doesn't work as expected. The HTTPS request always fail.
It only works if I only use one instance of WiFiClientSecure. However during the HTTPS request I am disconnected of the MQTT server.
Is this behavior is due to hardware limitation ?
Here is the revelant part of code
WiFiClientSecure espClient;
WiFiClientSecure espClient2;
PubSubClient mqttClient(espClient);
const char* rootCABuff = \
"-----BEGIN CERTIFICATE-----\n" \
...
"-----END CERTIFICATE-----\n";
void setup() {
/* Connect to wifi then set cert*/
espClient.setCACert(rootCABuff);
espClient2.setCACert(rootCABuff);
/* Define clock or will fail*/
setClock();
...
client.setServer("myserver", myport); // MQTT server
...
}
void loop() {
...
if (!mqttclient.connected()) {
reconnect();
}
else
{
mqttclient.loop();
}
...
/*Sometimes a https request is needed*/
HTTPClient http;
http.setTimeout(10000);
char* baserequest = "https://myserver.com";
httpRequestData="somedata";
Serial.print("[HTTPS] begin...\n");
if (http.begin(espClient2, baserequest)) { // HTTPS
http.addHeader("Accept", "application/json");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
Serial.print("[HTTPS] POST...\n");
int httpCode = http.POST(httpRequestData);
http.end();
} else {
Serial.printf("[HTTPS] Unable to connect\n");
}
...
}

ESP8266 AccessPoint always fails after exactly 5 times of correct communications

i'm practicing with ESP8266 since few months,in Arduino IDE.
I tried to understand fundamentals reading Neil Kolban Book,but still i can't master the callback mechanism,and lot of other stuff,because my lack of experience in networks .
Now communication is between my PC and NodeMCU,using TCP/IP,and i'm trying to detect data reception by a led blink(or a print on terminal)without any wifi related function called inside the loop.
I am referring to this example https://internetofhomethings.com/homethings/?tag=using-sdk-functions-with-arduino-ide,using only a basic part of the code,
but for some reason,if i try to connect by a PC or a cellphone or a ESP12 StationPoint, it works only 5 times from reset.
Using a PC or cellphone, if i type in the address bar of a browser 192.168.4.15 i have the blink after pressing Enter key,but only for 5 times.
If i print received data:
**
GET / HTTP/1.1
Host: 192.168.4.15
Connection: keep-alive
Cache-Control: max-age=0
DNT: 1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml
+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-
exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7**
Please can you check the code?I'm spending hours every day trying to understand something .
Many thanks,
Diego
#include <ESP8266WiFi.h>
#define SVRPORT 80
unsigned char blink_flag;
// Include API-Headers
extern "C" {
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
//#include "mem_manager.h"
//#include "mem.h"
//#include "string.h"
#include "user_interface.h"
#include "cont.h"
#include "espconn.h"
#include "eagle_soc.h"
#include <pgmspace.h>
void * pvPortZalloc(int size,char *, int);
}
/* _ _
/\ (_) | |
/ \ ___ ___ ___ ___ ___ _ __ ___ _ _ __ | |_
/ /\ \ / __/ __/ _ \/ __/ __| | '_ \ / _ \| | '_ \| __|
/ ____ \ (_| (_| __/\__ \__ \ | |_) | (_) | | | | | |_
/_/ \_\___\___\___||___/___/ | .__/ \___/|_|_| |_|\__|
| |
|_| */
byte ledPin = 2;
const IPAddress ipadd(192,168,4,15);
const IPAddress ipgat(192,168,4,1);
const IPAddress ipsub(255,255,255,0);
//***************************************************
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
WiFi.mode(WIFI_AP);
WiFi.softAP("MyTest_AP_Id", "MyTest_AP_pw");
WiFi.softAPConfig(ipadd, ipgat, ipsub);
SdkWebServer_Init(SVRPORT);
Serial.println();
Serial.println("accesspoint_bare_01.ino");
Serial.println("Server started.");
Serial.print("IP: "); Serial.println(WiFi.softAPIP());
Serial.print("MAC:"); Serial.println(WiFi.softAPmacAddress());
blink_led(4,400);
}
//************************************************************************************
void loop() {
if(blink_flag)//if SdkWebServer_recv is triggered do a recognizable blink
{
blink_flag=0;//to stop blinking until new data is received
blink_led(8,100);
}
}
/********************************************************
* SDK API Web Server Initialization
* Function: SdkWebServer_Init(int port)
********************************************************/
void SdkWebServer_Init(int port) {
LOCAL struct espconn esp_conn;
LOCAL esp_tcp esptcp;
//Fill the connection structure, including "listen" port
esp_conn.type = ESPCONN_TCP; //This is the type of connection we are going to use
esp_conn.state = ESPCONN_NONE;//The state of the connection will change over time but we initialize it to have an initial empty state by supplying ESPCONN_NONE.
esp_conn.proto.tcp = &esptcp;//structure called "esp_tcp". This structure contains TCP specific
//settings. For our story, this is where we supply the port number which our TCP connection will
//listen upon for client connections. This is supplied in the property called "local_port".
esp_conn.proto.tcp->local_port = port;//80 for TCP/IP
esp_conn.recv_callback = NULL;
esp_conn.sent_callback = NULL;
esp_conn.reverse = NULL;
//Register the connection timeout(0=no timeout)
espconn_regist_time(&esp_conn,0,0);
//Register connection callback
espconn_regist_connectcb(&esp_conn, SdkWebServer_listen);//funzioni di libreria
//espconn_regist_disconcb (&esp_conn, MiaDiscCallback);
//Start Listening for connections
espconn_accept(&esp_conn);
Serial.print("Web Server initialized: Type = SDK API\n");
}
/********************************************************
* SDK API Web Server TCP Client Connection Callback
* Function: SdkWebServer_listen(void *arg)
********************************************************/
void SdkWebServer_listen(void *arg)
{
struct espconn *pesp_conn = ( espconn *)arg;
espconn_regist_recvcb(pesp_conn, SdkWebServer_recv);
espconn_regist_reconcb(pesp_conn, SdkWebServer_recon);
espconn_regist_disconcb(pesp_conn, SdkWebServer_discon);
}
//************************************************************************************
void SdkWebServer_recv(void *arg, char *pData, unsigned short len)
{
struct espconn *ptrespconn = ( espconn *)arg;
espconn_set_opt(ptrespconn, ESPCONN_REUSEADDR);
blink_flag=1;
}
/********************************************************
* SDK API Web Server TCP Connection Closed Callback
* Function: SdkWebServer_discon(void *arg)
********************************************************/
void SdkWebServer_discon(void *arg)
{
struct espconn *pesp_conn = ( espconn *)arg;
}
/********************************************************
* SDK API Web Server TCP Disconnect on error Callback
* Function: SdkWebServer_recon(void *arg, sint8 err)
********************************************************/
void SdkWebServer_recon(void *arg, sint8 err)
{
struct espconn *pesp_conn = ( espconn *)arg;
}
//************************************************************************************
void blink_led(unsigned char reps,unsigned int del)
{
while(reps--)
{
digitalWrite(ledPin,HIGH);
delay(del);
digitalWrite(ledPin,LOW);
delay(del);
}
}
//************************************************************************************
Why are you using the SDK functions with Arduino code? There are good Arduino Core web >servers that are much easier to use
Why are you using the SDK functions with Arduino code? There are good Arduino Core web >servers that are much easier to use
Hello .I dont know what is better to use,i'm not an expert ESP8266 user..
I need that for an application that would need another post to be explained and i tried to put the question simple.
That application failed wifi after few minutes,reading on web I've found that it was probably because i managed wrongly WiFi inside the loop.
The example I've started from seemed inviting because all about wifi looks managed by callbacks.
Is there any illegal use of SDK functions in Arduino code?
I was not able to configure any other environment as Eclipse,it was a nightmare of many days of environment variables,paths and forbidden folder names with spaces.
Probably i will try other Arduino examples that i recently was told about,the ones using inside the loop
void loop() {
server.handleClient(); //Handling of incoming client requests
}
Anyway i'm still looking for an explanation about the reason why my code fails exactly after 5 times,regardless of receiving 20 bytes or 400 bytes(and this makes me think that is not because the 1460 bytes of TCP blocks,but i dont want to do any assumption).
Thanks.

How is the ESP32 (DOIT DevKit) finding another host in the same LAN via mDNS?

I have a Raspberry Pi connected to my Wifi LAN that responds to mDNS as mqtt-broker.local.
I can find it on my laptop with this command:
$ avahi-resolve-host-name -4 mqtt-broker.local
mqtt-broker.local 192.168.XXX.YYY
I have an ESP32 DOIT DevKit device that can send messages to the Raspberry Pi via Wifi if I use the IP address 192.168.XXX.YYY, however I would like my ESP32 to resolve the host using mDNS.
I am not able to get the mDNS working, the code at the bottom prints:
Finding the mDNS details...
No services found...
Done finding the mDNS details...
What's wrong with this code?
What should I put as service in MDNS.queryService("mqtt-broker", "tcp")? I have tried even with service mqtt with no luck, however this shouldn't matter, the mDNS stuff should work regardless what's exposed from the Raspberry Pi (HTTP server, MQTT, FTP whatever...)
Checking here https://github.com/espressif/arduino-esp32/blob/master/libraries/ESPmDNS/src/ESPmDNS.h#L98 there is not that much information about this "service" and "proto", and I am not that much familiar with low-level C/C++, what are these things?
This is the code I am using:
// import the headers
#include <ESPmDNS.h>
void findMyPi() {
Serial.println("Finding the mDNS details...");
// make sure we are connected to the Wifi
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.println("Not yet connected to Wifi...");
}
if (!MDNS.begin("whatever_this_could_be_anything")) {
Serial.println("Error setting up MDNS responder!");
}
// what should I put in here as "service"?
int n = MDNS.queryService("mqtt-broker", "tcp");
if (n == 0) {
Serial.println("No services found...");
}
else {
for (int i = 0; i < n; ++i) {
// Print details for each service found
Serial.print(" ");
Serial.print(i + 1);
Serial.print(": ");
Serial.print(MDNS.hostname(i)); // "mqtt-broker" ??? How can I find it???
Serial.print(" (");
Serial.print(MDNS.IP(i));
Serial.print(":");
Serial.print(MDNS.port(i));
Serial.println(")");
}
}
Serial.println("Done finding the mDNS details...");
}
This function has been inspired by this example:
https://github.com/espressif/arduino-esp32/blob/master/libraries/ESPmDNS/examples/mDNS-SD_Extended/mDNS-SD_Extended.ino
Ended up using a different method from the class on that mDNS library provided by Espressif (ESPmDNS.h), a combination of:
IPAddress serverIp = MDNS.queryHost(mDnsHost);
while loop on this check serverIp.toString() == "0.0.0.0"
This is the code that glues up all together:
// on my laptop (Ubuntu) the equivalent command is: `avahi-resolve-host-name -4 mqtt-broker.local`
String findMDNS(String mDnsHost) {
// the input mDnsHost is e.g. "mqtt-broker" from "mqtt-broker.local"
Serial.println("Finding the mDNS details...");
// Need to make sure that we're connected to the wifi first
while (WiFi.status() != WL_CONNECTED) {
delay(250);
Serial.print(".");
}
if (!MDNS.begin("esp32whatever")) {
Serial.println("Error setting up MDNS responder!");
} else {
Serial.println("Finished intitializing the MDNS client...");
}
Serial.println("mDNS responder started");
IPAddress serverIp = MDNS.queryHost(mDnsHost);
while (serverIp.toString() == "0.0.0.0") {
Serial.println("Trying again to resolve mDNS");
delay(250);
serverIp = MDNS.queryHost(mDnsHost);
}
Serial.print("IP address of server: ");
Serial.println(serverIp.toString());
Serial.println("Done finding the mDNS details...");
return serverIp.toString();
}

Couchbase Server to iOS Phone

I'm developing an iOS application.
Little bit confused about implementing the login module which the (Username/Password, Register and Forgot Password).
New to Couchbase. Used the Couchbase Enterprise Editon "http://192.168.1.126:8091/ui/index.html#/overview" Set up the Couchbase Lite in Xcode and I dunno what's the next step. Does anyone knows?
Data Modeling: Documents JSON
User ("Set as the EMAIL ID")
{
_id:” ",
username::" ",
password::" ",
email::" ",
type:"user"
}
User Info ("Set as the EMAIL ID")
{
_id:” ",
description:" ",
fb_URL::" ",
Twitter::" ",
Gender::" ",
Age::"[min:, max:]",
type:"user"
}
Users can be created in the Sync Gateway configuration file like so:
{
"databases": {
"app": {
"bucket": "walrus",
"users": {
"john": {"password": "pass"}
}
}
}
}
Then, authentication in the iOS app is enabled for this user:
let manager = CBLManager.sharedInstance()
let database = try! manager.databaseNamed("app")
let url = NSURL(string: "http://localhost:4984/app")!
let push = database.createPushReplication(url)
let pull = database.createPullReplication(url)
push.authenticator = CBLAuthenticator.basicAuthenticatorWithName("john", password: "pass")
pull.authenticator = CBLAuthenticator.basicAuthenticatorWithName("john", password: "pass")
push.start()
pull.start()
For user registration, you'll need to set up an App Server to register users on the Sync Gateway Admin port (4985 by default). To register a user:
$ curl -vX POST -H 'Content-Type: application/json' \
-d '{"name": "user2", "password": "pass"}' \
:4985/app/_user/
For the forgotten password functionality, the App Server should update the user record with the new password:
$ curl -vX PUT -H 'Content-Type: application/json' \
-d '{"name": "user2", "password": "newpass"}' \
:4985/app/_user/user2

Resources