error: 'serverHandshake' was not declared in this scope - socket.io

#include <WebSocketClient.h>
#include <string.h>
#include <stdlib.h>
#include <Arduino.h>
#include <SocketIOClient.h>
#include <EEPROM.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <WiFi.h>
#define SSID "D"
#define PASS "qwertypoiu"
int keyIndex = 0; // your network key Index number
int status = WL_IDLE_STATUS;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "ec2-52-38-82-235.us-west-2.compute.amazonaws.com:8000";
WebSocketClient client;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
SoftwareSerial esp8266Module(10,11);
Serial.begin(9600);
Ethernet.begin(mac);
client.connect("update trash");
}
}
void loop() {
// put your main code here, to run repeatedly:
client.monitor();
client.send("56fe4b3368fa1b0edd4b44a1,30");
delay(2000);
}
Above is my code i am unable to compile code .error is serverHandshake' was not declared in this scope . I can't any solution . Any help from your side will be appreciated .

Related

How to operate at24c32 by smbus in linux?

What if the EEPROM used is greater than 32K, such as at24c32, and the register address is 16bit? It seems that smbus only supports 8bit registers?
I can read 0xff, but the written content will return - 5, which fails.
I want to know whether the kernel only supports 8-bit registers, but not 16 bit registers?
This is my code:
#include <fcntl.h>
#include <stdio.h>
#include <linux/i2c-dev.h>
#include <errno.h>
#include <stddef.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <linux/types.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <stdint.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <termios.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <signal.h>
#define AT24C32_ADDR 0x53
__s32 i2c_smbus_access(int file, char read_write, __u8 command,
int size, union i2c_smbus_data* data)
{
struct i2c_smbus_ioctl_data args;
__s32 err;
args.read_write = read_write;
args.command = command;
args.size = size;
args.data = data;
err = ioctl(file, I2C_SMBUS, &args);
if (err == -1)
err = -errno;
return err;
}
__s32 i2c_smbus_write_byte_data(int file, __u8 command, __u8 value)
{
union i2c_smbus_data data;
data.byte = value;
return i2c_smbus_access(file, I2C_SMBUS_WRITE, command,
I2C_SMBUS_BYTE_DATA, &data);
}
__s32 i2c_smbus_read_byte_data(int file, __u8 command)
{
union i2c_smbus_data data;
int err;
err = i2c_smbus_access(file, I2C_SMBUS_READ, command,
I2C_SMBUS_BYTE_DATA, &data);
if (err < 0)
return err;
return 0x0FF & data.byte;
}
static int32_t i2c_smbus_write_word_data(int file, uint8_t cmd, uint16_t value)
{
union i2c_smbus_data data;
data.word = value;
return i2c_smbus_access(file, I2C_SMBUS_WRITE, cmd,
I2C_SMBUS_WORD_DATA, &data);
}
static int32_t i2c_smbus_read_word_data(int fd, uint8_t cmd)
{
union i2c_smbus_data data;
int err;
err = i2c_smbus_access(fd, I2C_SMBUS_READ, cmd,
I2C_SMBUS_WORD_DATA, &data);
if (err < 0)
return err;
return data.word;
}
int set_slave_addr(int file, int address, int force)
{
/* With force, let the user read from/write to the registers
even when a driver is also running */
if (ioctl(file, force ? I2C_SLAVE_FORCE : I2C_SLAVE, address) < 0) {
fprintf(stderr,
"Error: Could not set address to 0x%02x: %s\n",
address, strerror(errno));
return -errno;
}
return 0;
}

Data loss SPI communication (Master Slave) (ESP32)

I am trying to make a simple SPI Master/slave comunication between two ESP32, using this code as reference https://github.com/hideakitai/ESP32DMASPI
My code is (master) :
#include <stdio.h>
#include <stdint.h>
#include <Arduino.h>
#include "maspn18_e3_a_r2_c_can_cr09338.h"
#include <ESP32DMASPIMaster.h>
//#include <ESP32DMASPISlave.h>
#include <ESP32CAN.h>
#include <CAN_config.h>
#include <iostream>
#include <stdlib.h>
//#include <SPI.h>
/*
#include <string.h>
#include <math.h>
*/
// === [ START ] Master Configuration ===
ESP32DMASPI::Master master;
static const uint32_t BUFFER_SIZE = 8; // deve essere un multiplo di 4 ==> 8192
uint8_t* spi_master_tx_buf;
//uint8_t* spi_master_rx_buf;
uint8_t num_msg = 0;
uint8_t msg_src[]= {num_msg, 0x80, 0x4A, 0x0F, 0x00, 0x00, 0x00, 0x00};
//uint8_t msg_src[]= {0x00, 0x80, 0x4A, 0x0F, 0x00, 0x00, 0x00, 0x00};
void set_buffer() {
for (uint32_t i = 0; i < BUFFER_SIZE; i++) {
spi_master_tx_buf[i] = msg_src[i];
//spi_master_tx_buf[i] = i & 0xFF;
}
//memset(spi_master_rx_buf, 0, BUFFER_SIZE);
}
// === [ STOP ] Master Configuration ===
using namespace std;
CAN_device_t CAN_cfg; // CAN Config
const int rx_queue_size = 10; // Receive Queue size
void setup() {
Serial.begin(115200);
Serial.println("CAN reader on primary CAN bus - MASTER SPI");
//CAN_cfg.speed = CAN_SPEED_500KBPS;
//CAN_cfg.tx_pin_id = GPIO_NUM_22;
//CAN_cfg.rx_pin_id = GPIO_NUM_21;
//CAN_cfg.rx_queue = xQueueCreate(rx_queue_size, sizeof(CAN_frame_t));
//////////// Init CAN Module
//ESP32Can.CANInit();
// === [ START ] Master setup ===
// to use DMA buffer, use these methods to allocate buffer
spi_master_tx_buf = master.allocDMABuffer(BUFFER_SIZE);
//spi_master_rx_buf = master.allocDMABuffer(BUFFER_SIZE);
set_buffer();
delay(5000);
master.setDataMode(SPI_MODE0); // default: SPI_MODE0
master.setFrequency(4000000); // default: 8MHz (too fast for bread board...) // 4000000
master.setMaxTransferSize(BUFFER_SIZE); // default: 4092 bytes
// begin() after setting
Serial.println("master.begin() - default: VSPI (CS: 5, CLK: 18, MOSI: 23, MISO: 19)");
master.begin(VSPI); // default: HSPI (CS: 15, CLK: 14, MOSI: 13, MISO: 12)
// === [ STOP ] Master setup ===
}
void loop() {
master.transfer(spi_master_tx_buf, BUFFER_SIZE);
printf("[%d] Send data ==>\n", msg_src[0]);
msg_src[0]++;
for (uint32_t i = 0; i < BUFFER_SIZE; i++) {
spi_master_tx_buf[i] = msg_src[i];
//spi_master_tx_buf[i] = i & 0xFF;
}
delay(2000);
// === [ STOP ] Master loop ===
}
And for the slave :
#include <stdio.h>
#include <stdint.h>
#include <Arduino.h>
#include "maspn18_e3_a_r2_c_can_cr09338.h"
#include <ESP32DMASPISlave.h>
#include <ESP32CAN.h>
#include <CAN_config.h>
#include <iostream>
#include <stdlib.h>
#include <SPI.h>
/*
#include <string.h>
#include <math.h>
*/
// MASTER SPI ==> https://github.com/hideakitai/ESP32DMASPI/blob/master/examples/master_simple/master_simple.ino
ESP32DMASPI::Slave slave;
static const uint32_t BUFFER_SIZE = 8; // 8192
//uint8_t* spi_slave_tx_buf;
uint8_t* spi_slave_rx_buf;
using namespace std;
CAN_device_t CAN_cfg; // CAN Config
const int rx_queue_size = 10; // Receive Queue size
void setup() {
Serial.begin(115200);
Serial.println("CAN writer on second CAN bus - SLAVE SPI");
spi_slave_rx_buf = slave.allocDMABuffer(BUFFER_SIZE);
//set_buffer();
delay(5000);
// slave device configuration
slave.setDataMode(SPI_MODE0);
slave.setMaxTransferSize(BUFFER_SIZE);
// begin() after setting
//slave.begin(); // HSPI = CS: 15, CLK: 14, MOSI: 13, MISO: 12 -> default
// VSPI (CS: 5, CLK: 18, MOSI: 23, MISO: 19)
Serial.println("slave.begin(VSPI); - VSPI (CS: 5, CLK: 18, MOSI: 23, MISO: 19)");
slave.begin(VSPI);
}
void loop() {
// if there is no transaction in queue, add transaction
if (slave.remained() == 0) {
//slave.queue(spi_slave_rx_buf, spi_slave_tx_buf, BUFFER_SIZE);
slave.queue(spi_slave_rx_buf, BUFFER_SIZE);
}
// if transaction has completed from master,
// available() returns size of results of transaction,
// and buffer is automatically updated
while (slave.available()) {
printf("Received data ==> ");
// show received data
for (size_t i = 0; i < BUFFER_SIZE; ++i) {
printf("%d ", spi_slave_rx_buf[i]);
}
printf("\n");
slave.pop();
}
}
Basically it just sends a simple array over and over again with an incremental number in the first place. However, apparently at random, the comunication will "skip" a number or it will print the same a couple of time and then skip it. Image for reference :
Print of the received message on the slave:
What could be the cause of this problem?
I tried altering the frequence of the communication and i tried varying the buffer size to the smallest possible, but it does not seem to have any effect
Thanks a lot in advance

ipref3 dll for windows

I try to build ipref3.dll for windows
I found How to compile iperf3 for Windows
Built it but i got only iperf3.exe and libiperf.a
I found, how create dll manual
gcc -s -shared -o iperf3.dll units.o timer.o tcp_window_size.o tcp_info.o net.o iperf_util.o iperf_sctp.o iperf_udp.o iperf_tcp.o iperf_server_api.o iperf_locale.o iperf_client_api.o iperf_error.o iperf_api.o cjson.o -Wl,--enable-auto-import,--export-all-symbols,--subsystem,windows
after i found how need to initialize
HMODULE h = LoadLibrary(TEXT("cygwin1.dll"));
PFN_CYGWIN_DLL_INIT init = (PFN_CYGWIN_DLL_INIT)GetProcAddress(h, "cygwin_dll_init");
init();
Now i can load dll and make initialization but when i start test iperf_run_client application is crashed
Unhandled exception at 0x611537C0 (cygwin1.dll) in iprerf-server.exe:
0xC0000005: Access violation reading location 0x00740000.
How can solve this problem?
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <WinSock2.h>
//#include <unistd.h>
#include <string.h>
//#include <sysexits.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#include "iperf_api.h"
#ifdef WIN64
#pragma comment(lib, "iperf3_64.lib")
#else
#pragma comment(lib, "iperf3.lib")
#endif
#pragma comment(lib, "ws2_32.lib")
typedef void *register_frame();
typedef int *hello_f();
typedef int(*PFN_HELLO)();
typedef void(*PFN_CYGWIN_DLL_INIT)();
#pragma pack(push, 1)
int main(int argc, char** argv)
{
WSADATA wsaData;
int wsaErr = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (wsaErr != 0) {
printf("WSAStartup failed with error: %d\n", wsaErr);
return 1;
}
//PFN_HELLO fnHello;
HMODULE /*hLib, */h = LoadLibrary(TEXT("cygwin1.dll"));
PFN_CYGWIN_DLL_INIT init = (PFN_CYGWIN_DLL_INIT)GetProcAddress(h, "cygwin_dll_init");
init();
char* argv0;
char* host;
int port;
struct iperf_test *test;
argv0 = strrchr(argv[0], '/');
if (argv0 != (char*)0)
++argv0;
else
argv0 = argv[0];
if (argc != 3) {
fprintf(stderr, "usage: %s [host] [port]\n", argv0);
exit(EXIT_FAILURE);
}
host = argv[1];
port = atoi(argv[2]);
test = iperf_new_test();
if (test == NULL) {
fprintf(stderr, "%s: failed to create test\n", argv0);
exit(EXIT_FAILURE);
}
iperf_defaults(test);
iperf_set_verbose(test, 1);
iperf_set_test_role(test, 'c');
iperf_set_test_server_hostname(test, host);
iperf_set_test_server_port(test, port);
/* iperf_set_test_reverse( test, 1 ); */
iperf_set_test_omit(test, 3);
iperf_set_test_duration(test, 5);
iperf_set_test_reporter_interval(test, 1);
iperf_set_test_stats_interval(test, 1);
/* iperf_set_test_json_output( test, 1 ); */
if (iperf_run_client(test) < 0) {
fprintf(stderr, "%s: error - %s\n", argv0, iperf_strerror(i_errno));
exit(EXIT_FAILURE);
}
if (iperf_get_test_json_output_string(test)) {
fprintf(iperf_get_test_outfile(test), "%zd bytes of JSON emitted\n",
strlen(iperf_get_test_json_output_string(test)));
}
iperf_free_test(test);
exit(EXIT_SUCCESS);
}
The reason why the shared lib is not built is:
libtool: warning: undefined symbols not allowed in x86_64-unknown-cygwin
shared libraries; building static only
the easy way to bypass it, in a clean build is to use:
$ make libiperf_la_LIBADD="-no-undefined"
The build will include the shared libray and the import library
$ find . -name "*dll*"
./src/.libs/cygiperf-0.dll
./src/.libs/libiperf.dll.a
For what I see to make a build on cygwin is also needed to remove a definition
in src/iperf_config.h after running configure
/* #define HAVE_SETPROCESSAFFINITYMASK 1 */
PS #1: iperf-2.0.5-1 is available as cygwin package
PS #2: your code is Windows-like while Cygwin is a Unix-like system, you can not mix them
I found solution
1) It need to create addition dll: my_crt0.dll
#include <sys/cygwin.h>
#include <stdlib.h>
typedef int (*MainFunc) (int argc, char *argv[], char **env);
void my_crt0 (MainFunc f)
{
cygwin_crt0(f);
}
gcc -c my_crt0.c
gcc -o my_crt0.dll my_crt0.o -s -shared -Wl,--subsystem,windows,--enable-auto-import,--export-all-symbols,--out-implib,my_crt0.lib
2) Modify main code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <WinSock2.h>
#include <string.h>
#include "iperf_api.h"
#pragma comment(lib, "iperf3.lib")
#pragma comment(lib, "ws2_32.lib")
typedef int(*MainFunc) (int argc, char *argv[], char **env);
typedef void(*my_crt0)(MainFunc f);
int main2(int argc, char** argv, char **env)
{
char* argv0;
char* host;
int port;
struct iperf_test *test;
host = (char*)"127.0.0.1";
port = 4000;
test = iperf_new_test();
if (test == NULL) {
exit(EXIT_FAILURE);
}
iperf_defaults(test);
iperf_set_verbose(test, 1);
iperf_set_test_role(test, 'c');
iperf_set_test_server_hostname(test, host);
iperf_set_test_server_port(test, port);
/* iperf_set_test_reverse( test, 1 ); */
iperf_set_test_omit(test, 3);
iperf_set_test_duration(test, 5);
iperf_set_test_reporter_interval(test, 1);
iperf_set_test_stats_interval(test, 1);
/* iperf_set_test_json_output( test, 1 ); */
iperf_strerror(0);
if (iperf_run_client(test) < 0) {
fprintf(stderr, "%s: error - %s\n", argv0, iperf_strerror(i_errno));
exit(EXIT_FAILURE);
}
if (iperf_get_test_json_output_string(test)) {
fprintf(iperf_get_test_outfile(test), "%zd bytes of JSON emitted\n",
strlen(iperf_get_test_json_output_string(test)));
}
iperf_free_test(test);
exit(EXIT_SUCCESS);
return 1;
}
int main(int argc, char** argv)
{
WSADATA wsaData;
int wsaErr = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (wsaErr != 0) {
printf("WSAStartup failed with error: %d\n", wsaErr);
return 1;
}
{
HMODULE /*hLib, */h = LoadLibrary(TEXT("my_crt0.dll"));
my_crt0 init = (my_crt0)GetProcAddress(h, "my_crt0");
init(main2);
}
exit(EXIT_SUCCESS);
}
Now it compiled and worked to VS 2015

Boost using async_write sends strange data

I'm trying to develop a simple chat program using Boost. I came accross strange situation. I use netcat to listen at specific port while I run the program that's sending a simple text. Connection is established but the text is messed up. Actually instead of whole line I sometimes get one random characters or two. Im putting the code down below:
#include "lib/client.h"
#include <boost/asio.hpp>
#include <boost/asio/io_service.hpp>
#include <iostream>
#include <thread>
#include <string>
int main(int argc, char* argv[]){
if(argc != 3){
std::cout << "Wrong use. After specifying executable, add host and port\n";
return 0;
}
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver(io_service);
auto endpoint = resolver.resolve({argv[1],argv[2]});
Client c(io_service, endpoint);
std::thread t([&io_service](){ io_service.run();});
std::string text = "Welcome host!";
c.add_msg_to_deque(text);
t.join();
c.close();
return 0;
}
And here are client methods:
#include "../lib/client.h"
#include <boost/asio.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/array.hpp>
#include <deque>
#include <iostream>
#include <string>
void Client::connect(boost::asio::ip::tcp::resolver::iterator endpoint){
boost::asio::async_connect(socket, endpoint,
[this](boost::system::error_code ec, boost::asio::ip::tcp::resolver::iterator)
{
if (!ec)
{
}
});
}
void Client::close()
{
ios.post([this]() { socket.close(); });
}
void Client::add_msg_to_deque(const std::string& msg){
ios.post([this,msg](){
write_msg_deque.push_back(msg);
send_msg();
});
}
void Client::send_msg(){
boost::array<char,128> buf;
std::string temp_string = write_msg_deque.front();
std::copy(temp_string.begin(),temp_string.end(),buf.begin());
boost::asio::async_write(socket, boost::asio::buffer(buf,temp_string.size()),[this](boost::system::error_code ec, std::size_t){
if(!ec){
write_msg_deque.pop_front();
if(!write_msg_deque.empty())
send_msg();
}
else{
socket.close();
}
});
}
You are using async_write with local data it is bad idea. async_write returns immediately. After calling async_write your method send_msg terminates, so local data (buf array) is destroyed before your message is sent. You can use a synchronous version of IO functions to send data or keep buf as member of your class to provide data exists until data is sent successfully.

Application crashes says : Access violation reading location 0xbaadf04d

I m doing project in opencv... i m getting error like this
"Unhandled exception at 0x775a15ee in touch.exe: 0xC0000005: Access violation reading location 0xbaadf04d."
the code is
using namespace std;
#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include "math.h"
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <sstream>
int main(int argc, char* argv[]){
//declerations
CvCapture *frame=0;
IplImage *image=0;
cvNamedWindow( "Image taken", CV_WINDOW_AUTOSIZE );
frame=cvCreateCameraCapture(2);
frame=cvCreateCameraCapture(2);
image = cvQueryFrame(frame);
cvShowImage("Image taken", image);
cvWaitKey(0);
return 0;
}
Try replacing
frame=cvCreateCameraCapture(2);
with
frame=cvCreateCameraCapture(-1);
if (!frame) {
puts("Couldn't detect a camera.");
return(1);
}

Resources