Hi guys,
I'd like to send a data from Arduino M0 with WINC1500 and Arduino Uno with ESP8266. But I can't do this.
So I post my code and I hope you could help me.
Arduino M0 with WINC1500:
#include <SPI.h>
#include <WiFi101.h>
#include <WiFiUDP.h>
char ssid_ap[] = "Arduino"; // created AP name
char pass_ap[] = ""; // (not supported yet)
int status = WL_IDLE_STATUS;
unsigned int localPort = 2390; // local port to listen on
char packetBuffer[255]; //buffer to hold incoming packet
char ReplyBuffer[] = "ok"; // a string to send back
WiFiServer server_ap(80);
WiFiClient client_ap;
WiFiUDP Udp;
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
}
Serial.println();
// 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("Creating Network named: ");
Serial.println(ssid_ap);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.beginAP(ssid_ap);
// wait 10 seconds for connection:
delay(10000);
server_ap.begin();
}
Serial.println("Connected to wifi");
Udp.begin(localPort);
printWifiStatus();
}
void loop() {
int packetSize;
client_ap = server_ap.available();
if (client_ap) { // if you get a client,
Serial.println("new client"); // print a message out the serial port
// if there's data available, read a packet
packetSize = Udp.parsePacket();
if (packetSize)
{
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remoteIp = Udp.remoteIP();
Serial.print(remoteIp);
Serial.print(", port ");
Serial.println(Udp.remotePort());
// read the packet into packetBufffer
int len = Udp.read(packetBuffer, 255);
if (len > 0) packetBuffer[len] = 0;
Serial.println("Contents:");
Serial.println(packetBuffer);
// send a reply, to the IP address and port that sent us the packet we received
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
} // print it out the serial monitor
// close the connection:
client_ap.stop();
Serial.println("client disconnected");
}//Fine AP
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
And the code of Arduino Uno with ESP8266:
#include "ESP8266.h"
#define SSID "Arduino"
#define PASSWORD ""
#define HOST_NAME "192.168.1.1"
#define HOST_PORT (2390)
ESP8266 wifi(Serial);
void setup(void)
{
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version:");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.disableMUX()) {
Serial.print("single ok\r\n");
} else {
Serial.print("single err\r\n");
}
Serial.print("setup end\r\n");
}
void loop(void)
{
uint8_t buffer[128] = {0};
if (wifi.registerUDP(HOST_NAME, HOST_PORT)) {
Serial.print("register udp ok\r\n");
} else {
Serial.print("register udp err\r\n");
}
char *hello = "Hello, this is client!";
wifi.send((const uint8_t*)hello, strlen(hello));
uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
if (len > 0) {
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
}
if (wifi.unregisterUDP()) {
Serial.print("unregister udp ok\r\n");
} else {
Serial.print("unregister udp err\r\n");
}
delay(5000);
}
The Arduino with ESP sends "Hello this is the client!" and the other answers "ok".
But the Arduino with ESP8266 doesn't connect to WINC1500 line.
Could you help me?
Thanks