Closed ocrdu closed 5 years ago
Hi,
the Arduino Nano has very less RAM an no real C++ support. there is the ATmega branche (https://github.com/Links2004/arduinoWebSockets/tree/ATmega) to get around the C++ problem, but most likely the Arduino Nano has to less RAM. you can try it if you like.
you can try to add
#undef max
#undef min
before the includes, but since the Arduino pre compiler does many strange things in the background im am not sure if this will work. If you are using a real IDE you have a better change with this.
Note: the ATmega branche has less features and keeps the functionality at the bare minimum to fit the AVR controllers.
This is one of the "new" Nano's, with an ARM Cortex-M0+ CPU, 256K flash and 32KB SRAM; basically an Arduino MKR WiFi 1010 on a smaller PCB.
But thanks, I'll have a go and muck about with it some more.
FYI: One compile error left now:
C:\Documents and Settings\odu.PC1\Desktop\websocket\websocket.ino: In function 'void onWebSocketEvent(uint8_t, WStype_t, uint8_t*, size_t)':
websocket:27:34: error: 'class WebSocketsServer' has no member named 'remoteIP'
IPAddress ip = webSocket.remoteIP(num);
^~~~~~~~
exit status 1
'class WebSocketsServer' has no member named 'remoteIP'
Probably an unknown WEBSOCKETS_NETWORK_TYPE.
Code now is (undefs added, printfs replaced):
#undef max
#undef min
#include <WiFiNINA.h>
#include <WebSocketsServer.h>
#include "arduino_secrets.h"
char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
// Globals
WebSocketsServer webSocket = WebSocketsServer(80);
// Called when receiving any WebSocket message
void onWebSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
// Figure out the type of WebSocket event
switch(type) {
// Client has disconnected
case WStype_DISCONNECTED:
Serial.print((char) num);
Serial.println(" disconnected!");
break;
// New client has connected
case WStype_CONNECTED: {
IPAddress ip = webSocket.remoteIP(num);
Serial.print((char) num);
Serial.print("Connection from ");
Serial.println(ip);
}
break;
// Echo text message back to client
case WStype_TEXT:
Serial.print((char) num);
Serial.print(" Text: ");
Serial.println((char*) payload);
webSocket.sendTXT(num, payload);
break;
// For everything else: do nothing
case WStype_BIN:
case WStype_ERROR:
case WStype_FRAGMENT_TEXT_START:
case WStype_FRAGMENT_BIN_START:
case WStype_FRAGMENT:
case WStype_FRAGMENT_FIN:
default:
break;
}
}
void setup() {
// Start Serial port
Serial.begin(9600);
// Connect to access point
Serial.println("Connecting");
WiFi.begin(ssid, pass);
while ( WiFi.status() != WL_CONNECTED ) {
delay(500);
Serial.print(".");
}
// Print our IP address
Serial.println("Connected!");
Serial.print("My IP address: ");
Serial.println(WiFi.localIP());
// Start WebSocket server and assign callback
webSocket.begin();
webSocket.onEvent(onWebSocketEvent);
}
void loop() {
// Look for and handle WebSocket data
webSocket.loop();
}
Time to dig further into the library and see what's what.
The non ESP network stack has no get remote IP function, hence the function is not implemented.
you need to remove the remoteIP
call.
IPAddress ip = webSocket.remoteIP(num);
Serial.print((char) num);
Serial.print("Connection from ");
Serial.println(ip);
If you able to get it working, i will add the code to the examples if you like.
I am having this problem as well.. any progress?
No progress from me at least; I was in a hurry and have implemented the web interface I was making with SSE instead of a websocket; I will look into it again when I have more time.
SSE?
That would work for me! I too am in a rush..
Might you have any example code you used to get it working? :)
John
On Mon, Sep 9, 2019 at 10:50 AM Oscar den Uijl notifications@github.com wrote:
No progress from me at least; I was in a hurry and have implemented the web interface I was making with SSE instead of a websocket; I will look into it again when I have more time.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Links2004/arduinoWebSockets/issues/468?email_source=notifications&email_token=AMGUXMZTNW6VZ5TFY36BXE3QIZPENA5CNFSM4ISNTD4KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6H3WMQ#issuecomment-529513266, or mute the thread https://github.com/notifications/unsubscribe-auth/AMGUXM775EC5Q672CCW2RXDQIZPENANCNFSM4ISNTD4A .
--
John Reine CGSN Electrical Engineering Lead Woods Hole Oceanographic Institution LOSOS Bldg., MS#57 Woods Hole, MA 02543 phone: 508-289-3336 email: jreine@whoi.edu
The code I use is here: https://github.com/ocrdu/arduino-webinterface-sse
No documentation yet; try at your own risk 8-).
First of all, many thanks for making the Websockets library for the Arduino.
Now, prepare for some clueless questions 8-) about this library:
I saw that there is no support for the following hardware: Arduino Nano 33 IoT. Will there be?
Stubborn as I am, I tried to use the library with said hardware, and the WiFiNINA library. I couldn't get things to compile; I got the infamous 'macro "min" passed 3 arguments, but takes just 2' error. Is there a way to get around that?
The error is below, and the code is below that.
Thanks in advance for any and all time you may want to put into answering my questions.
Mit freundlichen Grüßen,
Oscar.
Error:
Code: