Basically, my project uses a force-sensing resistor to detect occupancy on the chair. The ESP8266 WiFi would wake from the sleep mode and send an update to the server. If there is no occupancy, the ESP8266 goes back to sleep.
My project uses Wiolink, a dev board that uses a ESP8266 WiFi chip. Hence, it is quite impossible to connect GPIO 16 to RST to wake up ( or reset ) the device.
Deep sleep is predefined at a set amount of time using this function ESP.deepsleep(). Is it possible to wake up with an external interrupt such as the force sensing resistor?
String apiKey = ""; // const char* ssid = ""; // wifi username const
char* password = ""; // wifi password
void setup() // Defines the initial condition of the hardware board.
{
Serial.begin(115200); delay(10);
}
void loop() // Defines the loop condition of the hardware board. {
sensorReading = analogRead(A0);
if(sensorReading >= 150) // Condition when someone is sitting;
{
//Wake ESP8266
//perform server update
}
if(sensorReading <=149) // Condition for no one sitting;
{
Serial.println("Going into deep sleep");
ESP.deepSleep(); //
}
Related
on my code i can send an sms to my target number but i don't know how to read or receive sms from target number
the tinyGSM library doesn't have the read member function and i don't know how to use AT commands
void setup() {
// Set console baud rate
SerialMon.begin(115200);
// Keep power when running from battery
Wire.begin(I2C_SDA, I2C_SCL);
bool isOk = setPowerBoostKeepOn(1);
SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));
// Set modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(3000);
// Restart SIM800 module, it takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
modem.restart();
// use modem.init() if you don't need the complete restart
// Unlock your SIM card with a PIN if needed
if (strlen(simPIN) && modem.getSimStatus() != 3 ) {
modem.simUnlock(simPIN);
}
// To send an SMS, call modem.sendSMS(SMS_TARGET, smsMessage)
String smsMessage = "Hello from ESP32!";
/*if(modem.sendSMS(SMS_TARGET, smsMessage))
{
SerialMon.println(smsMessage);
}
else{
SerialMon.println("SMS failed to send");
}*/
SerialAT.println("AT"); //Once the handshake test is successful, it will back to OK
SerialAT.println("AT+CMGF=1"); // Configuring TEXT mode
SerialAT.println("AT+CNMI=1,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
}
void loop()
{
//readSMS(1);
//delay(1);
}
I have tried a lot of times, but any solution doesn't work.
I'm using an ESP32 as a Control and HC-05 as an anthena for an Arduino UNO.
I make that the HC-05 could read every String it recieves, but I'm not able to link the ESP32 (DevKit v1) with it. This is my code. I tried using address or name, but none of them works, only return "Failed to connect". But I can find it.
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
String MACadd = "00:19:08:35:31:63"; // HC-05 Address: 19:8:353163 (Given by the HC-05)
uint8_t address[6] = {0x00, 0x19, 0x08, 0x35, 0x31, 0x63};
String name = "AUTO"; // The name I put, I can find this by my mobile phone
char *pin = "1234"; //<- standard pin would be provided by default
bool connected;
void setup()
{
Serial.begin(115200);
SerialBT.begin("ESP32_Control", true);
SerialBT.setPin(pin);
Serial.println("The device started in master mode, make sure remote BT device is on!");
connected = SerialBT.connect(name);
if(connected)
Serial.println("Connected Succesfully!");
else
while(!SerialBT.connected(10000))
Serial.println("Failed to connect. Make sure remote device is available and in range, then restart app.");
if (SerialBT.disconnect()) // disconnect() may take upto 10 secs max
Serial.println("Disconnected Succesfully!");
SerialBT.connect(); // this would reconnect to the name(will use address, if resolved) or address used with connect(name/address).
}
void loop()
{
if (Serial.available())
SerialBT.write(Serial.read());
if (SerialBT.available())
Serial.write(SerialBT.read());
delay(20);
}
i'm working on an IoT project which needs to connect to a laravel based socket server.
on laravel side all things are working just as should be but the problem is in arduino side which is a ESP8266 module being program by Arduino IDE.
i want to use Links2004/arduinoWebSockets library to connect to server.
it connects but i can't determine on which channel it should be.
is there any way on this library to tell the channel device should be on?
I gratefully appreciate any help :)
Arduino Test Code:
/*
Esp8266 Websockets Client
This sketch:
1. Connects to a WiFi network
2. Connects to a Websockets server
3. Sends the websockets server a message ("Hello Server")
4. Prints all incoming messages while the connection is open
Hardware:
For this sketch you only need an ESP8266 board.
Created 15/02/2019
By Gil Maimon
https://github.com/gilmaimon/ArduinoWebsockets
*/
#include <ArduinoWebsockets.h>
#include <ESP8266WiFi.h>
const char* ssid = "****"; //Enter SSID
const char* password = "******"; //Enter Password
const char* websockets_server_host = "xxx.xxx.xxx.xxx"; //Enter server adress -- serverip_or_name
const uint16_t websockets_server_port = 6001; // Enter server port
bool connected;
using namespace websockets;
WebsocketsClient client;
void setup() {
Serial.begin(115200);
// Connect to wifi
WiFi.begin(ssid, password);
// Wait some time to connect to wifi
for(int i = 0; i < 10 && WiFi.status() != WL_CONNECTED; i++) {
Serial.print(".");
delay(1000);
}
// Check if connected to wifi
if(WiFi.status() != WL_CONNECTED) {
Serial.println("No Wifi!");
return;
}
Serial.println("Connected to Wifi, Connecting to server.");
// try to connect to Websockets server
connected = client.connect(websockets_server_host, websockets_server_port, "/app/ab_key");
if(connected) {
Serial.println("Connecetd!");
client.send("Hello Server");
} else {
Serial.println("Not Connected!");
}
// run callback when messages are received
client.onMessage([&](WebsocketsMessage message) {
Serial.print("Got Message: ");
Serial.println(message.data());
});
}
void loop() {
if(connected) {
Serial.println("Connecetd!");
client.send("Hello Server");
} else {
connected = client.connect(websockets_server_host, websockets_server_port, "/app/ab_key");
Serial.println("try!");
}
// let the websockets client check for incoming messages
if(client.available()) {
client.poll();
}
delay(500);
}
terminal view of laravel websocket: laravel websocket
I am testing a BLE module (HC-08), which looks like a UART to the Arduino Uno.
This should be simple, but I have spent hours trying to build a string or char array from the response from commands sent over the software serial port.
first, here's the code:
#include <SoftwareSerial.h>
int data = 0;
SoftwareSerial Blue(10, 11); // RX, TX
void setup() {
Serial.begin(115200);
Blue.begin(9600);
Serial.println("BLE_Test started");
}
void loop() {
Blue.write("AT+VERSION?");
if (Blue.available()) {
data = Blue.read();
Serial.write(data);
}
delay(50);
}
And here's the output:
BLE_Test started
OK:SH-V1.251
OK:SH-V1.251
OK:SH-V1.251
OK:SH-V1.251
Each line ends with a CR-LF (13,10), so it looks fine on the screen.
So, here's my problem.
How can I build a string or char array out of the bytes coming from the BLE module? My goal is to make a function that simply sends a command string to the BLE module and return a string from the function. (Similar to Serial.readstring(), but SoftwareSerial has no readstring() property).
Like I said, it should be straightforward, but I am getting nowhere. Any tips would be appreciated.
it is readString with capital S and it is implemented in Stream which is a common base class for Serial implementations and SoftwareSerial and many other classes like LCD, EthernetClient, WiFiClient, ...
Doh!
That works, here's my working code:
//Send the command to the BLE module, returns with response in global inData
void getBlue(char* blueCmd) {
inData = "";
Blue.write(blueCmd);
delay(15);
while (Blue.available() > 0)
{
inData = Blue.readString();
}
}
I am having an issue trying to send commands to my Arduino Mega from my Android Xamarin.Forms app. When i use Bluetooth terminal app from play store it works, but my code does not. In the Arduino terminal i am just getting squares as if it is a baud rate issue or something. but from what i can see the baud rate is always determined by the device, which defaults to 9600 for the HM10.
I am using this library for the bluetooth https://github.com/xabre/xamarin-bluetooth-le
Arduino Sketch (works with bt terminal app)
void loop()
{
// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (Serial3.available())
{
byte y = Serial3.read();
//int x = (int)y;
Serial.write(y);
}
// Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available())
{
c = Serial.read();
// do not send line end characters to the HM-10
if (c != 10 & c != 13)
{
Serial3.write(c);
}
// Echo the user input to the main window.
// If there is a new line print the ">" character.
if (NL) { Serial.print("\r\n>"); NL = false; }
Serial.write(c);
if (c == 10) { NL = true; }
}
}
Then my send code in my Xamarin.Forms app
private async Task Button_ClickedAsync(object sender, EventArgs e)
{
if (_charataristice != null && _charataristice.CanWrite)
{
var data = Convert.ToByte(16);
_charataristice.WriteType = CharacteristicWriteType.WithoutResponse;
await _charataristice.WriteAsync(new[] { data });
}
}
Would appreciate any help, the value i am trying to revive is alwasy a number and should fall within one byte.