saesf / IOTNode

MIT License
1 stars 0 forks source link

Need Help #1

Open Val-charlet opened 1 year ago

Val-charlet commented 1 year ago

I am having the B-L475E-IOTO1A dico kit and i would like to extract data from the two microphones, i tried your code but i don't know how to get back the data with TeraTerm.

saesf commented 1 year ago

Hi, I assume you want to receive data using serial port on teraterm. In order to do that, you need send them using USART1 module. This can be done using either printf function or HAL api for usart.

HAL_UART_Transmit(&huart1, (uint8_t *)payloadBuffers[0], payload_len,1000);
//        HAL_UART_Transmit_DMA(&huart1, (uint8_t *)payloadBuffers[0], payload_len);
//        while(UARTTXCompleteFlag==0);

This is a simple code that can send payload using uart1. You can add this to first four if conditions of the main loop and bypass the queue entirely, i should also mention that the throughput of usart1 is very low so you need to lower the sampling rate of microphones.

if(micDma0HlfCmplt==1)
{
 micDma0HlfCmplt=0;
 HAL_UART_Transmit(&huart1, (uint8_t *)payloadBuffers[0], payload_len,1000);
}
Val-charlet commented 1 year ago

Thanks for that it works good, with your initial code you get the data with a python script ? if I want to use the WIFI I have to create a python script ?

saesf commented 1 year ago

I send the data to a UDP server. you can use any software that can act as a UDP server or write one yourself using python. This is the code for a simple UDP server in python. You should also set SSID and password of your wifi network and IP/PORT of your UDP server in this file.

Val-charlet commented 1 year ago

image I did this code to create my server

image And did this to the STM32CubeIDE but I can't get the data, and i don't really know where is the problem maybe the port is not listening ?

saesf commented 1 year ago

You need to change host parameter of python code to '0.0.0.0'. And in config.h, you should set IP address of your computer. Your computer should (preferably) be on the same network as your board. Here is a simple python code that works fine for me:

import socket

def get_ip():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.settimeout(0)
    try:
        # doesn't even have to be reachable
        s.connect(('10.254.254.254', 1))
        IP = s.getsockname()[0]
    except Exception:
        IP = '127.0.0.1'
    finally:
        s.close()
    return IP

IPAddr = get_ip()
print("set this ip in config.h:" + IPAddr)

UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
UDPServerSocket.bind(('0.0.0.0', 8080))
bufferSize = 4000
print("UDP server up and listening")
while (True):
    bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)

    message = bytesAddressPair[0]

    address = bytesAddressPair[1]

    clientMsg = "Message from Client:{}".format(message)
    clientIP = "Client IP Address:{}".format(address)

    print(clientMsg)
    print(clientIP)

You should also make some changes to my project. Comment out these two lines in main.c (line 314):

while(AccelGyroMeterInitialization()!=0)
   HAL_Delay(500);

And change these lines in wifi.c to use UDP instead of TCP (line 148):

    sendCommand(UDPCommand,strlen(UDPCommand));
//  sendCommand(TCPcommand,strlen(TCPcommand));
Val-charlet commented 1 year ago

image When I load the python script it tells me to put this IP but when I do a netstat -a i can't find this IP so i cannot find a port to put in config.h.

Secondly these 2 lines while(AccelGyroMeterInitialization()!=0) HAL_Delay(500);

For me these lines, you execute AccelGyroMeterInitialization()! until the value is 0 when it' 0 it means that the sensor is initialized I don't see a mistake here

saesf commented 1 year ago

You can use ifconfig in Linux or ipconfig in windows to get ip address of your network interface and use that in config file. The problem with these two lines is that they try to initialize AccelGyro on x-nucleo board. If you do not have any x-nucleo attached to your IOT board then the initialization would always fail. If you have a x-nucleo board then you can use these sensors without any problem.

Val-charlet commented 1 year ago

image image Here is my settings i made the changes but still not receiving idk why. And ok thanks yeah i only have the IoT board

saesf commented 1 year ago

Could you show me the output of ifconfig? Is your computer connected to the same wifi network? did you set the port correctly in both codes?

Val-charlet commented 1 year ago

image Yeah the pc and the board has the same connection, maybe the port is not set correctly in python script i think but i don't understand which line contains the port is it this : s.connect(('172.20.10.11',1 )) and i replace 1 by my port

saesf commented 1 year ago

Yes that's right. You should replace 1 with your port number. I had some problem with wifi security mode before. Are you sure the board is connected to the wifi network? You should check security mode of your wifi network. for me, i set it to "WPA-PSK/WPA2-PSK AUTO" in access point settings and set the security mode to 3 in WifiInit. Security mode is defined in line 21 of wifi.h. You can set it based on this table: test

I had some problem with other security mode and only 3 worked for me.

Val-charlet commented 1 year ago

i am doing this with a connection sharing with my phone because for now i cannot use my work wifi, i saw that it's WPA3 security : so what did i put here #define SECcommad "C3=4\r\n"

saesf commented 1 year ago

I think this wifi module doesn't support WPA3. Can you change your phone hotspot's security settings to "None"? if you use None then you can use C3=0.

saesf commented 1 year ago

I don't know. I haven't tested it myself.

Val-charlet commented 1 year ago

it's not possible i will try with WPA2 i don't have to change anything ?

saesf commented 1 year ago

WPA2 has 2 settings: TKIP or AES. you should use 3 for AES and 5 for TKIP. i have only tested AES with mode 3.

Val-charlet commented 1 year ago

Ok thanks I will try at home I hope it will works

Val-charlet commented 1 year ago

image last question when i have to choose a port i have to take an established port or a time_wait

saesf commented 1 year ago

Established ports are already taken by some other process so you can't use them. As far as i know these states are only relevant for statefull connection like TCP. UDP is stateless, hence there is no state for a UDP connection. Operating system always checks for free ports and if the port you choose is already taken, it will prevent your application for accessing it and your python code would throw an error.

Val-charlet commented 1 year ago

Did it works with a WPA2-CCMP ?

saesf commented 1 year ago

I don't know. I've only tested it with a 2.4 GHz wifi in "WPA-PSK/WPA2-PSK AUTO" mode and C3=3. Does your WiFi work in 2.4 GHz band or 5 GHz ?

Val-charlet commented 1 year ago

image i will try with wifi but i am not WPA2 :( at my job we use 5 gHz

saesf commented 1 year ago

According to datasheet you can use mode 2 or 4 for wpa. Have you tried them?

Val-charlet commented 1 year ago

image tried with 2 and 4 but still nothing...

saesf commented 1 year ago

Try uncommenting these two lines at the end of WifiInit function (line 156 of wifi.c).

sendCommand(SetSettingsSpace, strlen(SetSettingsSpace));
sendCommand(SaveSettings, strlen(SaveSettings));

And connect to a WPA2 wifi with C3=3. I've just tested it with my laptop's hotspot (WPA2-Personal, 2.4 GHz) and it works.

Val-charlet commented 1 year ago

I tried with a WPA2 personal 2,4 GHz, but nothing even with trying all the things you tell me maybe I am unlucky I don't know. image image

saesf commented 1 year ago

Does your board get listed on your access point's client list? for me it appears in less than a minute: image

saesf commented 1 year ago

According to this post, by default these devices can't connect to an access point on channel 11 or above.