I'd like to get a TCP based connection from an arduino to a node.JS server. I found an example, I've tried to run it but its throwing the errors below, would appreciate any help.
Error Messages Arduino: 1.6.6 Hourly Build 2015/09/24 05:43 (Windows 7), Board: "Arduino/Genuino Uno"
WARNING: Category '' in library ArduinoJson is not valid. Setting to 'Uncategorized'
socketio.ino: In function 'void hello(Client&, const char*)':
socketio:19: error: expected unqualified-id before '.' token
socketio.ino: In function 'void setup()':
socketio:38: error: invalid conversion from 'void (*)(Client&, const char*)' to 'void (*)(Client&, ArduinoJson::JsonArray&)' [-fpermissive]
In file included from socketio.ino:6:0:
C:\arduino_1.6.6\libraries\socket.io-arduino-client.2/SocketIOClient.h:56:8: error: initializing argument 2 of 'void SocketIOClient::setEventHandler(const char*, void (*)(Client&, ArduinoJson::JsonArray&))' [-fpermissive]
void setEventHandler(const char* eventName, void (*handler)(Client& client, JsonArray& data));
^
socketio:39: error: invalid conversion from 'void (*)(Client&, const char*)' to 'void (*)(Client&, ArduinoJson::JsonArray&)' [-fpermissive]
In file included from socketio.ino:6:0:
C:\arduino_1.6.6\libraries\socket.io-arduino-client.2/SocketIOClient.h:56:8: error: initializing argument 2 of 'void SocketIOClient::setEventHandler(const char*, void (*)(Client&, ArduinoJson::JsonArray&))' [-fpermissive]
void setEventHandler(const char* eventName, void (*handler)(Client& client, JsonArray& data));
^
exit status 1
expected unqualified-id before '.' token
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino Code
#include #include
#include <ArduinoJson.h>
#include <SocketIOClient.h>
EthernetClient ethClient;
SocketIOClient client(ethClient);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char hostname[] = "192.168.100.40";
int port = 3000;
// Socket.io "hello" EVENT handler
void hello(Client& client, char const * data) {
Serial.print("[hello] event happening: ");
Serial.println(data);
Client.emit("goodbye", "Arduino here, goodbye!");
}
// Socket.io "goodbye" EVENT handler
void goodbye(Client& client, char const * data) {
Serial.print("[goodbye] event happening: ");
Serial.println(data);
Serial.println("That is all.");
}
void setup() {
Serial.begin(9600);
Ethernet.begin(mac);
if(!client.connect(hostname, port)) {
Serial.println(F("Not connected."));
}
//Event hanlders
client.setEventHandler("hello", hello);
client.setEventHandler("goodbye", goodbye);
//Say hello to the server
client.emit("hello", "Arduino here, hello!");
}
void loop() {
client.monitor();
}
SocketIOClient.h
/*
socket.io-arduino-client: a Socket.IO client for the Arduino
Based on Bill Roy's Arduino Socket.IO Client (which is based on
Kevin Rohling's Arduino WebSocket Client) with event handling by
@dantaex
Copyright 2014 Quentin Pigné
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SocketIOClient_H
#define SocketIOClient_H
#include <Arduino.h>
#include <Client.h>
#include <SPI.h>
#include <ArduinoJson.h>
#include "HashMap.h"
//Length of static data buffers
#define DATA_BUFFER_LEN 200
#define SID_LEN 24
//Max size of the HashTable
#define HASH_SIZE 20
class SocketIOClient {
public:
SocketIOClient(Client& client);
//Public connection methods
bool connect(const char* hostname, int port = 80, const char* resource = "socket.io", const char* nsp = "/");
//Public event handling methods
void setEventHandler(const char* eventName, void (*handler)(Client& client, JsonArray& data));
//Public data emitting methods
void emit(const char* event, const char* data);
//Monitoring for incoming data
void monitor();
private:
//Connection attributes
Client& client;
char* hostname;
int port;
char* resource;
char* nsp;
char sid[SID_LEN];
//Incoming data reading attributes
char databuffer[DATA_BUFFER_LEN];
char* dataptr;
//Event handling attributes
int nbEvent;
static HashType<const char*, void(*)(Client& client, JsonArray& data)> hashRawArray[HASH_SIZE];
static HashMap<const char*, void(*)(Client& client, JsonArray& data)> eventHandlers;
//Private incoming data reading methods
bool waitForInput();
void eatHeader();
void readInput();
};
#endif