#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
i am using a esp8266 to connect to aurdino.
this is the simple program for esp8266. it is showing th error the wifi.h file directory is not found. please help me to fix this issue. i
To use the ESP8266 or even ESP32, you might download the board package. For that, you could go to Board Manager and search ESP8266 and download the package.
Tools > Board > Board Manager
After that you will be able to use all the libraries needed. The wifi.h is part of the main library.
Related
I have been trying to use WiFi.h, WebServer.h and EEPROM.h together with ArduinoIoTCloud.h and
Arduino_ConnectionHandler.h to be able to change the WiFi credentials if required without changing the sketch and reuploading it.
The problem is when moving;
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS)
inside void setup() wouldn't work whether with constant char of the credentials or after modifying it to read from the EEPROM, like
WiFiConnectionHandler ArduinoIoTPreferredConnection(esid.c_str(), epass.c_str());
Please, is there any way to change the WiFi credentials from a web browser?
The Code
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char DEVICE_LOGIN_NAME[] = "********************";
const char SSID[] = "SECRET_SSID"; // Network SSID (name)
const char PASS[] = "SECRET_OPTIONAL_PASS"; // Network password (use for WPA, or use as key for WEP)
const char DEVICE_KEY[] = "SECRET_DEVICE_KEY"; // Secret device password
void onTemperatureChange();
float temperature;
void initProperties()
{
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(temperature, READWRITE, ON_CHANGE, onTemperatureChange);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
void setup() {
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
}
void onTemperatureChange() {
}
So, when I add the code for the access point to write and read from the EEPROM, I then, o my knowledge, need to move this line inside the void setup.
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
For example
void setup() {
Serial.begin(9600);
delay(1500);
// Code for reading from EEPROM and the eeprom_SSID and eeprom_SSID_PASS will then pass to SSID and PASS Chars
//
initProperties();
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
After that, the ESP will be pushed to restart as the IoT library doesn't find the SSID and PASS.
I have tried to do so with Blynk and many other libraries, and it worked; I could enter the credentail by activating a server and creating an access point to do so, and then blynk read from that and connected perfectly. The problem is that I have to use the Arduino IoT cloud, not Blynk.
Thanks for your support.
I received yesterday my brand new Arduino MKR GSM 1400 and started playing around with today.
However, I'm having trouble stablishing the connection with the SIM card. I'm using the "ReceiveSMS" example from the MKRGSM library (code below), but the execution is getting stuck at the gsmAccess.begin(PINNUMBER) command.
Using AT commands and the debug mode, I got the following description for the error message:
AT+CPIN?
+CME ERROR: SIM not inserted
I have tried connecting with 3 different SIM cards, all tested beforehand with a smartphone and confirmed to be functional. I have tried removing the PIN, but still got the same error.
Does anybody have any idea on what could be going wrong?
Thanks in advance
Code:
// include the GSM library
#include <MKRGSM.h>
#include "arduino_secrets.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[] = SECRET_PINNUMBER;
// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;
// Array to hold the number a SMS is retreived from
char senderNumber[20];
void setup() {
// initialize serial communications 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("SMS Messages Receiver");
// connection state
bool connected = false;
// Start GSM connection
while (!connected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
connected = true;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
Serial.println("Waiting for messages");
}
I'm really in need of help with this problem and as most commonly advised, I have researched and researched and researched for days and I can't figure out what's wrong...
With that being said, I'm working on a project that uses an ESP-32S (pinout) and an A6 GSM module. (pinout) I'm attempting to get them connected to have the A6 send data to ThingSpeak... My problem is that I can't get it to work... I have the exact same configuration between the two using an ESP8266 and it connects and works but with the ESP32S it just doesn't seem to work...
Below is the code I have used to connect the 32 to the A6 and everything says success and pass but it won't change any ThingSpeak values using any methods...
#define TINY_GSM_MODEM_A6
#include "TinyGsmClient.h"
#include "ThingSpeak.h"
#define SerialMon Serial
HardwareSerial SerialAT(1);
bool modemConeted;
// Your GPRS credentials
// Leave empty, if missing user or pass
const char apn[] = "wireless.twilio.com";
const char user[] = "";
const char pass[] = "";
bool dataSent = false;
TinyGsm modem(SerialAT);
TinyGsmClient client(modem);
void setup(){
SerialMon.begin(9600);
delay(1000);
gsmModSetup();
}
void gsmModSetup() {
// Set GSM module baud rate
SerialAT.begin(9600, SERIAL_8N1, 27, 26, false); //27 and 26 are the pins on the ESP32S connected to the U_Rxd/U_Txd pins of A6
delay(3000);
SerialMon.println("Initializing modem...");
modem.init();
delay(3000);
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.println(modemInfo);
SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork()) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
SerialMon.print("Connecting to ");
SerialMon.print(apn);
if (!modem.gprsConnect(apn, user, pass)) {
SerialMon.println(" fail");
delay(5000);
return;
}
SerialMon.println(" OK");
}
void loop(){
}
I'm using a Twilo Sim card that's loaded with data (as said above it works with esp8266 so not the SIM and not the board) The only part of this code that doesn't pass is the part that says GPRS connect. it never says pass or fail. It just sits for like five minutes then continues.
After this, I try and post to ThingSpeak and it gives ThingSpeak ERROR-307 which means failed to connect to ThingSpeak...
I have tried 2 different ways
The what I find the easy and normal way
ThingSpeak.setField(1, temp);
ThingSpeak.setField(2, h);
ThingSpeak.setField(3, p);
ThingSpeak.setField(4, pt);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
and the more complicated way of connecting to the server then sends a GET command with all the values put together with strings.
if (client.connect(thingSpeakAddress, 80))
{
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + WriteAPIKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(thingSpeakData.length());
client.print("\n\n");
client.print(thingSpeakData);
}
client.stop();
Yet neither work and I don't know what to do... My A6 is connected to the 32 using GPIO26 & 27 they're connected to the A6 U_Rxd/U_Txd pins. All boards share common ground as they should.
Any more guides to read or code to change or libraries to try would be extremely helpful as my days of digging has yielded nothing but frustration as one attempt after another fails. the readers of this really are my last hope in solving this problem that's hindering my farther progression.
(Any questions about anything on my end, please ask. -Thank you)
The enclose documentation shows ESP32S pins for HW Serial 0 RX/TX on pin GIPO01/GIPO03, HW Serial 1 RX/TX on pin GIPO09/GIPO10 Given you have attached no oter HW at the moment, why not try with the basic config with serial1Read about this: https://github.com/G6EJD/ESP32-Using-Hardware-Serial-Ports and use the latest core ESP32 package (as of today 23.3.2020 is 1.04, previous releases had issues with serial. Do notforget to setup the serial a given in the article its different to esp8266 (!) so much about code compability. If you use the code on both platforms, you have to work with
#ifdef ESP32
//configure serial for esp32
#elif ESP8266
//configure serial for esp8266
#else
#error "Hardware not supported"
#endif
Here a small test routine for just the serial communication. If you type something in the input line of serial monitor it should be mirrored in the output window
#include <HardwareSerial.h>
void setup() {
Serial.begin(9600);
// set the data rate for the HardwareSerial port
Serial2.begin(9600);
}
void loop() {
if (Serial2.available()) {
Serial.write(Serial2.read());
}
if (Serial.available()) {
Serial2.write(Serial.read());
}
}
You can then expand the serial2 to your settings. If it fails it may be dueto: U1UXD is unused and can be used for your projects. Some boards use this port for SPI Flash access though - so try Serial3.
I am able to transfer data from one arduino to another using nRF24L01 chips. However, I need the data to be sent ONLY when a specific command is sent on the serial port. I want to be able to write 'A' on the serial port, and for arduino to reply with the latest data. This is easy with the serialcommand library and works if I am directly plugged in. However, the moment I add the nRF24L01 module, serialcommand.h does not respond with the data anymore. I tried even removing the if (radio.available()) .. so no data would be received and just the fact that there is radio.begin() in setup makes the serialcommand 'A' not work. when I remove the radio stuff, the command 'A' does reply with three zeros (default data).
Here is my receiver code. I still consider myself a beginner and i never formally studied C/C++. Any help or ideas as to why this happens is very appreciated!
.
#include <SoftwareSerial.h>
#include <SerialCommand.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
SerialCommand sCmd;
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
int Array[3];
void setup() {
Serial.begin(9600);
sCmd.addCommand("A", serialdataPrint );
radio.begin();
radio.setRetries(15, 15);
radio.openReadingPipe(0,address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
while (Serial.available() > 0){
sCmd.readSerial();
if (radio.available()) {
int Array_received[3];
radio.read(&Array_received, sizeof(Array_received));
Array[0] = Array_received[0];
Array[1] = Array_received[1];
Array[2] = Array_received[2];
}
}
}
void serialdataPrint ()
{
Serial.println(Array[0]);
Serial.println(Array[1]);
Serial.println(Array[2]);
}
I am working on a project to send an email when a button is pressed using arduino uno, wifi module ESP8266, and the Blynk App. I was able to upload the sketch on the wifi module (ESP8266), but it's not responding. Here is the output that I am getting from the serial monitor:
len 1384, room 16
tail 8
chks
I have looked online and I can't find a solution to this. Can anyone one please help?
Below is the sketch that I am uploading.
Thanks in advance!
#include <Blynk.h>
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Set this to a bigger number, to enable sending longer messages */
#define BLYNK_MAX_SENDBYTES 128
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXXXXX";
char pass[] = "";
void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***
// Let's send an e-mail when you press the button
// connected to digital pin 2 on your Arduino
int isButtonPressed = !digitalRead(2); // Invert state, since button is "Active LOW"
if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
Blynk.email("xxxxxxx#gmail.com", "Subject: Button Logger", "You just pushed the button...");
// Or, if you want to use the email specified in the App (like for App Export):
//Blynk.email("Subject: Button Logger", "You just pushed the button...");
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepient's "e-mail address", "Subject" and the "message body"
Blynk.email("xxxxxx#gmail.com", "Subject", "My Blynk project is online.");
// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}
void loop()
{
Blynk.run();
}