I am trying to do an asynchronous web server using a Sparkfun ESP32 with an ESP32-WROOM-32D and the Arduino IDE for one of my projects. My ultimate goal is to use the WiFi network of the ESP32 as an AP and serve up an asynchronous web page to a connected client, so it can download a text file from the server.
To start my project, I tried to do a simple server just like in this tutorial :ESP32 Arduino: Asynchronous HTTP web server , I used the library ESPAsyncWebServer.h :
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
const char* ssid = "ESP32wifi";
const char* password = "12345679";
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(2000);
Serial.println("Connecting to Wifi...");
}
Serial.println("IP address: ");
Serial.print(WiFi.localIP());
server.on("/html", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/html", "<p>Hello!</p>");
});
server.begin();
}
void loop() {
}
The problem is that everytime I compiled the code there were no errors but when I opened the serial monitor in the Arduino IDE I was stuck in "Connecting to Wifi...", my WiFi.status was never connected.
I then try to solved the problem by reinstalling the libraries the program was using, change the SSID and the password of my network, change the server port to 8080 and use a code with a fixed IP address but my WiFi.status() was still the same.
A couple of days ago I used the same ESP32 as a Soft Access Point for another project with only the WiFi.h library :
#include "WiFi.h"
const char* ssid = "ESP32wifi";
const char* password = "12345679";
WiFiServer server(80);
I tried my old code again without the asynchronous server code and the SAP worked, so it wasn't a problem with the WiFi antenna. I then decided to try another kind of library that let me configure an asynchronous web server, it was WebServer.h :
#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "ESP32wifi";
const char* password = "12345679";
WebServer server(80);
But I had the same problem that I had with the AsyncWebServer, my program was stuck in "Connecting to Wifi..." .
So, my question is how can I configure an asynchronous web server in the ESP32 ?
Could it be a mistake in my code that causes my problem? Is there a way to use the WiFi.h library only for this kind of server?
Thank you in advance for your help !
Related
I have a UWA on RPi 3 with Win 10 version 10.0.14393.0 and VS 2015 Update 3. I'm trying to run a TCPListener on my RPi, code runs with no exception but never can connect it, seems that some things block my connection. there is no hardware or software Firewall in path. I tried both background and foreground app but no result.
My code is as below :
namespace TestBackPort
{
public sealed class StartupTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
TcpListener tcpListener = null;
tcpListener = new TcpListener(IPAddress.Parse("192.168.1.9"), 1100);
tcpListener.Start();
var task = HandleConnectionsAsync(tcpListener);
task.Wait();
}
int connectionNumber = 0;
async Task HandleConnectionsAsync(TcpListener listener)
{
while (true)
{
var client = await listener.AcceptTcpClientAsync();
// Console.WriteLine("OK #" + connectionNumber);
connectionNumber++;
}
}
}
}
First of all, check your network state using "netstat" utility.
Connect to your raspberry pi using putty or powershell
Do "netstate -a" to verify that the TCP server is actually listening on that port.
When you have your server running, you should see something similar to below
Secondly, make sure you have the Internet Server capability enabled in the project manifest file. It could be either the Internet or the Private Networks, like below.
import com.mchange.v2.c3p0.*;
import java.sql.*;
public class DBconnectionpool{
public static void main(String ar[]) throws Exception{
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass( "oracle.jdbc.driver.OracleDriver" );
cpds.setJdbcUrl( "jdbc:oracle:thin:#localhost:1521:xe" );
cpds.setUser("bms");
cpds.setPassword("abc");
cpds.setInitialPoolSize(5);
Connection con = cpds.getConnection();
System.out.println("got the connection"+con);
}
}
after Executing the above code ,In the Oracle monitor page i'm unable to see the 5 physical connections (i.e as i have set cpds.setInitialPoolSize(5)) instead i see only one connection.
your program exits immediately after one Connection is acquired. try sleeping for 30000 ms after you've acquired your Connection.
I want to download data using HttpConnection , see the example below
class ConnectionThread extends Thread
{
public void run()
{
try{
showToast("in the run method");
HttpConnection conn = null;
String URL = "http://xxxxxxx.com/api/api.php?func=showAllCountries;interface=wifi";
conn = (HttpConnection)Connector.open(URL);
}catch(Exception e){
showToast(e+"");
}
}
while running above code , on simulator it says Java.io.IOException No Wi-Fi connection found , Though in manage connection i can see simultor is conncted with Wifi ,
please why this is happening
Please
use deviceside= false;
in simulator wifi is not possible, simulator will access your system network , once you are on real device wifi will work if it is enabled in device.
Follow this link on how to make connections.
Trying to connect via Wi-Fi and I have an issue with the OS6 cd variable is null but it works on OS5
This is the url Strng: https://api3.popfax.com/index.php?service=Popfax;interface=wifi;interface=wifi
public ServiceConnectionBlackBerry(String s) throws IOException {
ConnectionFactory cf = new ConnectionFactory();
ConnectionDescriptor cd = cf.getConnection(s);
if (cd!=null){
connection = (HttpConnection) cd.getConnection();
}else {
System.out.println("Strng: "+s);}
}
can someone help please.
When using ConnectionFactory you should not append any connection information to your URL. So instead you should just pass https://api3.popfax.com/index.php?service=Popfax to your method.
Open a Wi-Fi HTTPS connection may help you.
thanks
The application is running perfect in device and simulator when i do use via eclipse, but when i will give cod file to client, it gives the following error, any idea?
this is the error:
net,rim.device.internal.io.CriticallOException: Critical tunnel failure
Create your network connection in another thread
new Thread(){
public void run(){
//connection stuff
}
}.start();
And add these settings to your url
String url += ";deviceside=true"
if(apn != null && !apn.trim.equals("")){
url += ";apn="+apn;
}
More information here http://supportforums.blackberry.com/t5/Java-Development/Critical-tunnel-failure/td-p/416396