Hı everyone
I am currently working on fingerprint module(fpm10).I read so many datasheet but every datasheet have different command packets I referenced R305 datasheet after that I wrote a Code for command packet to send STM32 but fpm10 doesnt send response to stm32.This is my verifypassword command packet Module send my receive my command packet but doesnt response.I debuged my cod and ı havent get any error
uint16_t FP_Verify_Password[16]={0xEF,0x01,0xFF,0xFF,0xFF,0xFF,0x01,0x00,0x07,0x13,0x00,0x00,0x00,0x00,0x00,0x05};
void Finger_Get_img(void)
{
delay_ms(500);
if(my_finger==true)
{
//only one time will be apply
for(i=6 ; i<=13 ; i++)
checksum+=FP_Verify_Password[i];
FP_Verify_Password[14]=checksum&0xFF00;
FP_Verify_Password[15]=checksum&0x00FF;
}
for(i=0;i<16;i++)
{
// USART_SendData(USART2,FP_Pack_Head[i]);
delay_ms(50);
USART_Finger(USART1,FP_Verify_Password[i]);
delay_ms(50);
USART_Finger(USART6,FP_Verify_Password[i]);
delay_ms(50);
}
delay_ms(2000);
// GPIO_ResetBits(GPIOG,GPIO_Pin_13);
my_finger=false;
}
Bluetooth and Finger print module config
//fingerprint module configurations
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
USART_InitStruct.USART_BaudRate=57600;
USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_InitStruct.USART_Parity=USART_Parity_No;
USART_InitStruct.USART_StopBits=USART_StopBits_1;
USART_InitStruct.USART_WordLength=USART_WordLength_8b;
USART_Init(USART1,&USART_InitStruct);
USART_Cmd(USART1,ENABLE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
//bluetooth module configurations
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART6);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_USART6);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOC,&GPIO_InitStruct);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);
USART_InitStruct.USART_BaudRate=9600;
USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStruct.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_InitStruct.USART_Parity=USART_Parity_No;
USART_InitStruct.USART_StopBits=USART_StopBits_1;
USART_InitStruct.USART_WordLength=USART_WordLength_8b;
USART_Init(USART6,&USART_InitStruct);
USART_Cmd(USART6,ENABLE);
This my command packet
Related
This is my first time working with Arduino, an esp32 and MQTT. I made a motion sensor that prints to an LCD when it senses movement and publishes a message to mqtt, but it loops on forever. I am trying to make it so it will only start when start is published through mqtt and stops when stop is published. However, I am having some trouble figuring it out. Here is my current code (the main part excluding the MQTT set up), and I've been told putting it in callback may help but I get an error saying "a function-definition is not allowed here before '{' token" referring to void loop. Any suggestions are appreciated.
void callback(char *topic, byte *payload, unsigned int length) {
Serial.print("Message arrived in topic: ");
Serial.println(topic);
Serial.print("Message:");
for (int i = 0; i < length; i++) {
Serial.print((char) payload[i]);
}
Serial.println();
Serial.println("-----------------------");
}
void loop() {
client.loop();
int motion = digitalRead(sensorPin);
if (motion == HIGH)
{
lcd.setCursor(0, 0);
lcd.print("!!!!!MOTION!!!!!");
client.publish(topic, "MOTION");
delay(100);
}
else
{
lcd.setCursor(0, 0);
lcd.print(" no motion ");
client.publish(topic, "NO MOTION");
delay(500);
}
}
first: why would you publish unlimited times on mqtt when motion is detected?
you detect the motion (digitalRead), publish it (i.e. with retain=true), and once published, set the flag i.e. published=true. Store the previous state of the motion and don't publish until it changed (either from motion to no-motion or vice versa).
Your code is publishing for ever when motion is detected (client.publish(topic, "MOTION");) or when motion is cleared (client.publish(topic, "NO MOTION");)
if I get you correctly: you want to publish motion state ONLY when the message on MQTT came: "start checking the motion", right?
if so, in callback you change the global variable i.e. "start_checking_motion = true" when message arrives (before the command on MQTT you set it to false)
Then in loop, first what you do is to check if start_checking_motion == true - if so, you perform the check of the motion and you publish - but again: only when motion changed - see the first paragraph of my post
Problem
Espressif's ESP-32 (specifically the ESP-WROOM-32 in this case) appears on a network with the default hostname "Espressif". I don't want to use this hostname, so I've opted to change it as follows:
// Initialize the TCP/IP adapter (launches handler task)
tcpip_adapter_init();
// Set the hostname for the default TCP/IP station interface
if ((err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, g_hostname))
!= ESP_OK) {
return err;
}
Of course, this isn't working. I get back the following error: ESP_ERR_TCPIP_ADAPTER_IF_NOT_READY.
Attempted Solutions
To solve this, I look to see if the TCP/IP adapter will post some kind of event when it is finished initializing. That way I can register a handler to set the hostname. The Espressif WiFi Driver Guide here indicates a task is launched - so there is probably an event right:
"The main task calls tcpip_adapter_init() to create an LwIP core task and initialize LwIP-related work."
Well I cannot find any such events. Neither the API documentation nor the actual file itself (tcpip_adapter.h) have it. I checked the header file for events, and none seem to exist solely for the purpose of indicating that the TCP/IP adapter has finished starting:
/** IP event declarations */
typedef enum {
IP_EVENT_STA_GOT_IP, /*!< ESP32 station got IP from connected AP */
IP_EVENT_STA_LOST_IP, /*!< ESP32 station lost IP and the IP is reset to 0 */
IP_EVENT_AP_STAIPASSIGNED, /*!< ESP32 soft-AP assign an IP to a connected station */
IP_EVENT_GOT_IP6, /*!< ESP32 station or ap or ethernet interface v6IP addr is preferred */
IP_EVENT_ETH_GOT_IP, /*!< ESP32 ethernet got IP from connected AP */
} ip_event_t;
Possible Lead
I have noticed that in Espressif's WiFi guide they indicate that the event SYSTEM_EVENT_STA_START (which indicates that a station has started), will:
Upon receiving this event, the event task will initialize the LwIP network interface (netif).
If I place the call after a handler receives this event, I no longer get the error:
// After the event WIFI_EVENT_STA_START
if (base == WIFI_EVENT && id == WIFI_EVENT_STA_START) {
// Set the hostname for the default TCP/IP station interface
if ((err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, g_hostname))
!= ESP_OK) {
fprintf(stderr, "Err: %s", esp_err_to_name(err));
}
...
}
However, the hostname still hasn't changed. Therefore I find myself a bit stuck. How can I actually change the hostname? I've found little to no results from searching this problem. However, the esp32 is a popular module and I'm sure many other people will find themselves facing the same problem.
Turns out I was doing it correctly. It was my router that had failed to refresh the hostname adequately. For consistency I will restate what I did to solve this problem:
The Espressif WiFi Guide indicates that the event SYSTEM_EVENT_STA_START is generated once esp_wifi_start() returns successfully.
The generation of this event also means that the event task will initialize the LwIP network interface (netif). Since we know that the TCP/IP adapter will surely have been initialized at this point, we can invoke the hostname change function. Here is an example of a handler that does that, taken right from their example:
void wifi_event_handler (void *handler_arg, esp_event_base_t base, int32_t id,
void *event_data) {
esp_err_t err;
// If esp_wifi_start() returned ESP_OK and WiFi mode is in station mode
if (base == WIFI_EVENT && id == WIFI_EVENT_STA_START) {
const char *name;
// Set the hostname for the default TCP/IP station interface
if ((err = tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, g_hostname))
!= ESP_OK) {
fprintf(stderr, "Err: %s", esp_err_to_name(err));
} else {
if ((err = tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_STA, &name)) != ESP_OK) {
fprintf(stderr, "Err Get Hostname: %s\n", esp_err_to_name(err));
} else {
printf("Hostname: %s\n", (name == NULL ? "<None>" : name));
}
}
...
}
...
}
In this example I get the hostname after setting it, and print it to stdout. You can validate it if you are running the monitor for the ESP32. The hostname set will be the one visible from the router page.
I am currently working on a project. I tried different sample testing code to send sms to my current number but it won't sent any.
Should my SIM 800L GSM module sim and my phone number have the same carrier?
I even followed the other people's advices on using a 3.7v power supply.
Library already included.
Correct RX-TX TX-RX, VCC, RST pins.
Below is a sample code from what I have been following.
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library!!
Sim800l Sim800l; //to declare the library
char* text;
char* number;
bool error; //to catch the response of sendSms
void setup(){
Sim800l.begin(); // initializate the library.
text="Testing Sms"; //text for the message.
number="2926451386"; //change to a valid number.
error=Sim800l.sendSms(number,text);
// OR
//Sim800l.sendSms("+540111111111","the text go here")
}
void loop(){
//do nothing
}
This should be sending a text message to a phone number but I am not receiving any.
My goal is to read the number of button press within a period(30s), upload it to a Microsoft SQl table using a php script. On the table, there is another column which adds in accumulated sum of the presses, which will be echo-ed back by the php script, and be read by the ESP8266 board.
So everything went through: I can read the count, upload it, read the accumulated sum back. The issue is it always takes ~5s in order to get a value back from the server. Attached is my troubleshooting:Serial Windows
It takes almost instantly to connect to the server(~100ms) but 5s to read the data that be echo-ed.
My guess was the php script takes time to run to the line where it echo out the value, but same delay(~5s) happens even if I tried a simple script(just echo).
Is this how the server behaves (not giving out the data right away) or is this how Arduino code (client.readStringUntil()) behaves?
Here is my code:
#include <SPI.h>
#include <ESP8266WiFi.h>
// Wifi Connection config
const char* ssid = "------";
const char* password = "------";
WiFiServer server(80);
IPAddress dbserver(10,1,1,138);
void setup_wifi()
{
delay(10);
// We start by connecting to a WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void setup()
{
Serial.begin(115200);
// Connect to WiFi network
setup_wifi();
}
void loop ()
{
WiFiClient client;
const int httpPort = 80;
bool conn = client.connect(dbserver,httpPort);
if (!conn) {
Serial.println("connection failed");
return;
}
else {
// call php script on the server(echo 1 value)
client.print("GET /test10.php HTTP/1.1");
client.println("Host: 10.1.1.138");
client.println("Connection: close");
client.println(); // Empty line
// Read from the server
Serial.println(millis()); // millis start reading
unsigned long timeout = millis();
while (client.available()==0){
if (millis()-timeout >1000){
Serial.println(">>> Client Timeout !");
client.stop();
}
}
Serial.println(millis()); // millis get the data stream
while (client.available()){
String line = client.readStringUntil('\r');
Serial.println(String(millis()) + " >>> "+line); // millis get each
// data line
}
delay(10);
client.stop(); // Closing connection to server
Serial.println("done");
}
delay(30000);
}
And is there any other way to fetch the data from the server to an ESP8266 module?
Thank you,
-Danny-
[SOLVED]: I need to set the Timeout parameter for the readStringUntil() function.
readStringUntil() is a blocking function. I will wait until it sees a char ('\r' in your case) or the timeout exceeds.
Just need to add client.setTimeout as:
WifiClient client;
client.setTimeout(10);
Still not sure if this practice is recommended, and how smaller should I go to for timeout?
Another solution would be using freeRTOS, and put the webserver in a separate task.
Then it can wait forever until a request is coming in.
I have recently started using Node-RED in a Raspberry Pi and my quest is to connect to a couple of I2C devices with the use of the node-red-contrib-i2c package.
One action which I am trying to do is to send an array of integers to the I2C device with the I2C output node but I always get the error
TypeError: String.isString is not a function
I have tried a couple of different syntax but without success. I have included an export of the flow below.
[{"id":"d2a2b073.e222c","type":"function","z":"e442e95f.6c2b98","name":"","func":"msg.address = 96;\nmsg.command = 48;\nmsg.payload = [85,85];\nreturn msg;","outputs":1,"noerr":0,"x":316,"y":243,"wires":[["7061e7e7.ac6f98","65101109.cf323"]]},{"id":"ce6f4bff.3bf998","type":"inject","z":"e442e95f.6c2b98","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":126,"y":244,"wires":[["d2a2b073.e222c"]]},{"id":"7061e7e7.ac6f98","type":"debug","z":"e442e95f.6c2b98","name":"","active":true,"console":"false","complete":"true","x":539,"y":263,"wires":[]},{"id":"65101109.cf323","type":"i2c out","z":"e442e95f.6c2b98","name":"","i2cdevice":"3d751c57.1120f4","address":"96","command":"","payload":"","count":"2","x":567,"y":223,"wires":[]},{"id":"3d751c57.1120f4","type":"i2c-device","z":"","device":"/dev/i2c-1","address":"100"}]
An example of the msg.payload sent:
msg.address = 96;
msg.command = 48;
msg.payload = [85,85];
return msg;