Salve ragazzi sta provando il modulo wifi per arduino "ESP-01" ho scaricato la libreria da github.com e ho provato a compilare questo programmino trovato in rete
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
// WiFi information
const char WIFI_SSID[] = "TP-LINK_N";
const char WIFI_PSK[] = "danilonunziata";
// Remote site information
const char http_site[] = "www.google.com";
const int http_port = 80;
// Pin definitions
const int LED_PIN = 5;
// Global variables
WiFiClient client;
void setup() {
// Set up serial console to read web page
Serial.begin(9600);
Serial.print("Thing GET Example");
// Set up LED for debugging
pinMode(LED_PIN, OUTPUT);
// Connect to WiFi
connectWiFi();
// Attempt to connect to website
if ( !getPage() ) {
Serial.println("GET request failed");
}
}
void loop() {
// If there are incoming bytes, print them
if ( client.available() ) {
char c = client.read();
Serial.print(c);
}
// If the server has disconnected, stop the client and WiFi
if ( !client.connected() ) {
Serial.println();
// Close socket and wait for disconnect from WiFi
client.stop();
if ( WiFi.status() != WL_DISCONNECTED ) {
WiFi.disconnect();
}
// Turn off LED
digitalWrite(LED_PIN, LOW);
// Do nothing
Serial.println("Finished Thing GET test");
while(true){
delay(1000);
}
}
}
// Attempt to connect to WiFi
void connectWiFi() {
byte led_status = 0;
// Set WiFi mode to station (client)
WiFi.mode(WIFI_STA);
// Initiate connection with SSID and PSK
WiFi.begin(WIFI_SSID, WIFI_PSK);
// Blink LED while we wait for WiFi connection
while ( WiFi.status() != WL_CONNECTED ) {
digitalWrite(LED_PIN, led_status);
led_status ^= 0x01;
delay(100);
}
// Turn LED on when we are connected
digitalWrite(LED_PIN, HIGH);
}
// Perform an HTTP GET request to a remote page
bool getPage() {
// Attempt to make a connection to the remote server
if ( !client.connect(http_site, http_port) ) {
return false;
}
// Make an HTTP GET request
client.println("GET /index.html HTTP/1.1");
client.print("Host: ");
client.println(http_site);
client.println("Connection: close");
client.println();
return true;
}
appena parte la compilazione mi dice
ATTENZIONE: la libreria ESP8266WiFi dichiara di funzionare sulle architetture [esp8266] e potrebbe non essere compatibile con la tua scheda che utilizza l'architettura [avr]
In file included from /home/danilo/Scrivania/arduino-1.6.6/libraries/ESP8266WiFi/src/ESP8266WiFi.h:33:0,
from /home/danilo/Arduino/wifiProvA/wifiProvA.ino:1:
/home/danilo/Scrivania/arduino-1.6.6/libraries/ESP8266WiFi/src/ESP8266WiFiType.h:26:19: fatal error: queue.h: No such file or directory #include <queue.h>
compilation terminated.
exit status 1
Errore durante la compilazione
Come posso risolvere ???
grazie buon fine settimana a tutti
ok ho capito che di default l'esp si interfaccia con arduino tramite comandi at , ma come faccio se voglio fare una richiesta http ad un evento su un sensore pir ????
Ragazzi scusata la mia assenza ma risco a lavorare a questo progetto solo il sabato mattina...
cmq stavo provando la libreria che ha postato SukkoPera ma credo che ci sia un problema di collegamento..
sto usando arduino uno e ho collegato tutto come nelle foto allegate
questo e il mio codice che ho preso dagli esempi della lib dovrebbe scansionare tutte le reti wifi...
ma mi va sempre in timeauto e mi deve che non trova l'esp
/*
WiFiEsp example: ScanNetworks
This example prints the Wifi shield's MAC address, and
scans for available Wifi networks using the Wifi shield.
Every ten seconds, it scans again. It doesn't actually
connect to any network, so no encryption scheme is specified.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
void setup() {
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue
while (true);
}
// Print WiFi MAC address
printMacAddress();
}
void loop()
{
// scan for existing networks
Serial.println();
Serial.println("Scanning available networks...");
listNetworks();
delay(10000);
}
void printMacAddress()
{
// get your MAC address
byte mac[6];
WiFi.macAddress(mac);
// print MAC address
char buf[20];
sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
Serial.print("MAC address: ");
Serial.println(buf);
}
void listNetworks()
{
// scan for nearby networks
int numSsid = WiFi.scanNetworks();
if (numSsid == -1) {
Serial.println("Couldn't get a wifi connection");
while (true);
}
// print the list of networks seen
Serial.print("Number of available networks:");
Serial.println(numSsid);
// print the network number and name for each network found
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
Serial.print(thisNet);
Serial.print(") ");
Serial.print(WiFi.SSID(thisNet));
Serial.print("\tSignal: ");
Serial.print(WiFi.RSSI(thisNet));
Serial.print(" dBm");
Serial.print("\tEncryption: ");
printEncryptionType(WiFi.encryptionType(thisNet));
}
}
void printEncryptionType(int thisType) {
// read the encryption type and print out the name
switch (thisType) {
case ENC_TYPE_WEP:
Serial.print("WEP");
break;
case ENC_TYPE_WPA_PSK:
Serial.print("WPA_PSK");
break;
case ENC_TYPE_WPA2_PSK:
Serial.print("WPA2_PSK");
break;
case ENC_TYPE_WPA_WPA2_PSK:
Serial.print("WPA_WPA2_PSK");
break;
case ENC_TYPE_NONE:
Serial.print("None");
break;
}
Serial.println();
}
ho fatto il collegamento come in quella foto allegata unica differenza che i pin rx-tx nn sono 0-1 ma 6-7
non ho utilizzato nessuno dei componenti che hai detto....non li conosco... potresti spiegarmi come fare e cosa sono... grazie
Io ho trovato più facile programmare i dispositivi in modo a se stante e poi farli comunicare in i2c
Nel mio caso esp che prende l'ora il meteo e le notizie rss tramite internet e poi le passa ad arduino tramite i2c che poi le visualizza su in display a matrice led, puoi provare a seguire questa via eventualmente , per me è risultata la via più semplice
Ciao grz per la risposta , puoi dirmi di piu su questo collegamento , in pratica se ho capito bene dovrei carcare un nuovo firmware sull'esp per poi programmarlo in modo tale da farlo comunicare con Arduino ????
Io dovrei mandare una semplice email quando viene letto un determinato codice rfid..
No non va caricato il firmware , va utilizzata la libreria per programmarlo con ide arduino , in pratica come se fosse una scheda arduino con il wifi , in tal senso è più pratico usare una scheda tipo wemos d1 o nodecmu che dispone di numerosi input output digitali e di uno analogico l'alimenti già a 5 volt con la porta usb con cui lo programmi direttamente , il lettore rdif puoi interfacciarlo direttamente ad una di queste schede e fare tutto con una sola scheda, ovviamente esistono lettori seriali , i2c o quelli economici a 4/5 fiili, trovi in giro su internet svariate guide su come programmare esp8266 con ide arduino