Comments (7)
Hi @drp0,
Here's an example sketch of how to intercept the event:
#include <SPI.h>
#include <WiFi101.h>
char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
WiFiServer server(23);
// new callbacks /////////////////////////////////////////////////////////
static void myResolve_cb(uint8_t * /* hostName */, uint32_t hostIp)
{
WiFi._resolve = hostIp;
}
void mySocketBufferCb(SOCKET sock, uint8 u8Msg, void *pvMsg)
{
socketBufferCb(sock, u8Msg, pvMsg); // call the original callback
if( u8Msg == SOCKET_MSG_ACCEPT) {
tstrSocketAcceptMsg *pstrAccept = (tstrSocketAcceptMsg *)pvMsg;
Serial.println("Accepted connection from: ");
IPAddress ip = pstrAccept->strAddr.sin_addr.s_addr;
Serial.print(ip);
Serial.print(":");
Serial.print(pstrAccept->strAddr.sin_port);
Serial.println();
}
}
///////////////////////////////////////////////////////////////////////////
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// override the original callbacks
registerSocketCallback(mySocketBufferCb, myResolve_cb);
// start the server:
server.begin();
}
void loop() {
// wait for a new client:
WiFiClient client = server.available();
// ...
}
I'm going to close this issue for now.
from wifi101.
I raised this way back in March?
It would be very surprising if Amtel had omitted to include a call to obtain the remote IP of the attached client in server/AP mode.
The lack of a library call to access the remote IP is a significant shortfall!
from wifi101.
Hi @drp0,
There is no API in the Atmel SDK to get the remote IP for a socket. However, when a server socket accepts a new connection the IP address and port of the client is provided via an event. So, it is possible to store this value for each socket. However, this would require 4 extra bytes per socket for each of the 7 TCP sockets available. If we also wanted to include the remote socket port, this would require another 2 bytes of storage per socket.
This would also introduce fragmentation to API's since the Arduino Client interface does not include support for retrieving the remote IP address of a connection. So, code that uses the new MKR1000 WiFiClient capabilities could not be used with other Client based network libraries.
from wifi101.
Hello Sandeep,
I understand the byte requirement.
I am using a mega so can absorb the increased code size.
Which library routine could be used to intercept the event? I would appreciate the opportunity of investigating the code potential.
David
from wifi101.
Hello Sandeep,
This works perfectly.
I can access the remote IP (and port) by storing them in global variables within the callback function:
then monitor the IP following an if client call……..
WiFiClient client = server.available();
if (client) {
……..
The client can be logged (and rejected if the ip is on a bad caller list)
Exactly as required.
It would be worth releasing this on the WIFI101 forum.
Thank you,
David
From: Sandeep Mistry [mailto:[email protected]]
Sent: 06 September 2016 22:07
To: arduino-libraries/WiFi101
Cc: drp0; Mention
Subject: Re: [arduino-libraries/WiFi101] A call to get the remote IP in Server or AP mode would be very useful ! (#40)
Hi @drp0 https://github.com/drp0 ,
Here's an example sketch of how to intercept the event:
#include <SPI.h>
#include <WiFi101.h>
char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
WiFiServer server(23);
// new callbacks /////////////////////////////////////////////////////////
static void myResolve_cb(uint8_t * /* hostName */, uint32_t hostIp)
{
WiFi._resolve = hostIp;
}
void mySocketBufferCb(SOCKET sock, uint8 u8Msg, void *pvMsg)
{
socketBufferCb(sock, u8Msg, pvMsg); // call the original callback
if( u8Msg == SOCKET_MSG_ACCEPT) {
tstrSocketAcceptMsg *pstrAccept = (tstrSocketAcceptMsg *)pvMsg;
Serial.println("Accepted connection from: ");
IPAddress ip = pstrAccept->strAddr.sin_addr.s_addr;
Serial.print(ip);
Serial.print(":");
Serial.print(pstrAccept->strAddr.sin_port);
Serial.println();
}
}
///////////////////////////////////////////////////////////////////////////
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// override the original callbacks
registerSocketCallback(mySocketBufferCb, myResolve_cb);
// start the server:
server.begin();
}
void loop() {
// wait for a new client:
WiFiClient client = server.available();
// ...
}
I'm going to close this issue for now.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub #40 (comment) , or mute the thread https://github.com/notifications/unsubscribe-auth/ANHAGrXoqGNrGAiuak1jZcFie_ABRmaaks5qndYOgaJpZM4HnPWM . https://github.com/notifications/beacon/ANHAGkVsQFkIbv91pUcID0sdFCNxb0jqks5qndYOgaJpZM4HnPWM.gif
from wifi101.
Hi @drp0,
Thanks for the feedback. Feel free to post a link to this Github issue on the forum.
from wifi101.
New API's for this have been added in pull request #207, the changes have been merged and will be released shortly.
from wifi101.
Related Issues (20)
- Compiler warning about buffer overflow in firmwareVersion() HOT 1
- 'if' statement at WifiClient.cpp:149 is useless HOT 1
- Wifi101 doesn't work once add the freeRTOS library HOT 3
- AP mode with WPA
- Modernize CI system
- HTTPS to sites using LetsEncrypt certificates with MKR1000 fails HOT 1
- Progressively slower transmission and potential buffer handling issue. HOT 5
- AP SSID goes back to default wifi101-xxxx after re-entering provision mode
- Add GitHub Actions workflow to synchronise with shared repository labels
- WiFi.ping(ip) freezes mkr1000 if WiFiUdp.h included
- Infinite stall on WiFiWebServer sample / MKR 1000 HOT 1
- WiFiServer simple improvements
- WiFi.hostname("MKR1000") function has no effects
- Multiple compilation problems on ESP8266 HOT 4
- Library does not work with WINC1500 and Mega2560 HOT 9
- Adafruit Feather M0 WiFi with uFL - ATSAMD21 + ATWINC1500 - fw 19.4.4
- Tx Power Mode
- Turn on WiFi hardware once turned off with WiFi.end()
- MKR1000 no connection with SSL (https) HOT 1
- ATWINC1500 with WiFi101 with MQTT always leads to a dead connection after some time HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wifi101.