RSSI value using MicroPython in NodeMCU ESP8266 - networking

How to get the RSSI value of the WLAN device connected to WiFi of my NodeMCU device using MicroPython? Actually I tried the following code but I'm getting an error:
>>> sta_if.ifconfig()
('192.168.1.103', '255.255.255.0', '192.168.1.1', '192.168.1.1')
>>> sta_if.rssi()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'WLAN' object has no attribute 'rssi'
I don't know what I should do to get the RSSI value of the network.

From the WLAN class documentation:
wlan.scan()
Scan for the available wireless networks.
Scanning is only possible on STA interface. Returns list of tuples with the information about WiFi access points:
(ssid, bssid, channel, RSSI, authmode, hidden)

Related

How to make text to speech on Raspberry Pi Pico W

I am trying to to make a simple voice assistant using python. However, after months of hard work, I realized that the TTS I was using (pyttsx3) will not load onto the Raspberry Pi Pico W. Is there any way to get TTS on the Pico?
I have tried using the Hugging face inference API for my code, so I used this snippet:
import network
import socket
import machine
import urequests as requests
ssid = 'My Wi-Fi network '
password = 'My Wi-Fi password'
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
print("internet connected sucessfully")
API_URL = "https://api-inference.huggingface.co/models/facebook/fastspeech2-en-ljspeech"
headers = {"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": "The answer to the universe is 42",
})
(Note that in my real code I put my actual API token and Wi-Fi password)
However, every time I run the code (with actual API token) it gives me the same error:
internet connected sucessfully
Traceback (most recent call last):
File "<stdin>", line 20, in <module>
File "<stdin>", line 17, in query
File "urequests.py", line 33, in json
File "urequests.py", line 20, in content
MemoryError: memory allocation failed, allocating 119296 bytes
what should I do?
The problem is the data volume it overpass the SRAM memory.
Please check out the Raspberry Pi Pico components and checkout what is a microcontroller. You always need put a program into a flash memory and create a comunication protocol, if you want use the Raspberry Pi Pico remotely.
https://datasheets.raspberrypi.com/pico/pico-product-brief.pdf
https://raspberrypi.github.io/pico-sdk-doxygen/modules.html

Serial port on Raspberry Pi disconnects after several minutes and cannot be reconnected (IOError, pyserial)

I have a device with a RS-232 DB9 port connected to my Raspberry Pi over a USB-to-serial cable.
Initially, I am able to communicate with the device without issue using pyserial.
However, after some variable length of time, I can no longer receive messages from the device.
If I close the serial port and attempt to open a new one, using the same code I normally use:
import serial
ser = serial.Serial(
serial_path,
9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE
)
I get:
File "/opt/venv/lib/python3.8/site-packages/serial/serialposix.py", line 713, in _update_dtr_state
fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str)
OSError: [Errno 5] Input/output error
I have no way to get around this error and re-establish communication with the device unless I physically unplug and replug the USB port.
In case it's relevant, the RS-232 device is connected to my RaspBerry Pi via an intermediate USB Hub and a USB extension cable.
I also tried setting rtscts=True and dsrdtr=True when creating the pyserial object. The IOError no longer occurs; however the serial device remains uncommunicative.
What might be the underlying issue here? Any guidance would be appreciated. Is there any way to detect the issue and reset the serial port via the shell, without requiring physical intervention?

Getting error on uploading code into esp8266 nodemcu by Arduino

Recently I bought a esp8266 nodemcu for my project.
For running the blink code, I followed this tutorial esp8266 quick start.
But ended up with this :
Sketch uses 246,319 bytes (23%) of program storage space.Maximum is 1,044,464 bytes.
Global variables use 32,276 bytes (39%) of dynamic memory, leaving 49,644 bytes for local variables.Maximum is 81,920 bytes.
Uploading 250464 bytes from C:\Users\test\AppData\Local\Temp\build544514107263874658.tmp/arduinowifi.cpp.bin to flash at 0x00000000
.error: failed sending 1044 bytes
error: failed sending 0xC0
warning: espcomm_send_command: didn't receive command response
warning: espcomm_send_command(FLASH_DOWNLOAD_DATA) failed
error: failed sending 0xC0
error: failed sending 8 bytes
error: failed sending 4 bytes
error: failed sending 0xC0
warning: espcomm_send_command: didn't receive command response
error: espcomm_upload_mem failed
I tried with different baud rate but failed.
Arduino IDE: 1.6.5 and 1.8.5
OS: Windows 10 and Ubuntu 16.04LTS
Update: Solved after using USB HUB.
The problem may come from circuit breakdown. I have this problem today and solved by following. Jump D3 (or GPIO00) to GND (if your PC still can see port). However, GPIO0 is set to OUTPUT/HIGH by default and may cause excessive current consumption. To prevent board fail, 1K resister may add between GPIO0(D3) and GND. Plug module power and upload program. Sometimes, please remember that you may need to unplug and plug module every new upload.
For another method,direct program to chip, use FTD232 (switch jumper to 3.3V) connect between FTD232 and NodeMCU like as Vcc(check it is 3.3V):3.3V , Tx:Rx, Rx:Tx, Gnd:Gnd, Gnd:D3. (you may use on board GND to D3)
Plug and upload. if the second method cannot work your ESP8266 IC may be gone.
As mention above, if your ESP8266 set GPIO0 as OUTPUT/HIGH, ground it may damage chip. Make sure that you
1) unplug power before ground GPIO0 (or add a resister)
2) power it and upload
3) remove GPIO0 when enter upload to prevent short out the output when program start to run.
First, you have to install the driver for the nodeMCU! You can get it here:
https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers
And then go to control panel->devices and check if your system detects the nodeMCU.
Next go to preferences and add the board to Arduino IDE
Next disconnect and reconnect (just for confirmation) to verify if a led(blue usually) blinks upon connection.
After these steps, then go to Arduino IDE and select the board as ESP -12E module
Set the programmer as AVRiSP mk ll
And then compile and upload!

RSSI determination using HM-10

I am using an arduino with HM-10 Bluetooth module. I am able to detect other HM-10(slave) in the vicinity of HM-10(master). In HM-10 datasheet AT+RSSI? command is mentioned which i tried with all possible combinations, but i am unable to extract the rssi value. Is there any way such that i can determine the rssi value using arduino on serial monitor. Any relevant code other than the command will be appreciated.
thanks in advance.
According to the "datasheet", "This command only used by Remote device query when connected."
Basically, to get this to work, you will need to set your slave to remote control mode with the AT command
AT+MODE2
Then, connect your master and slave. After this is done, you should be able to send the master the command "AT+RSSI?", it will send it to the slave, which will pick it up now that is in remote control mode. The slave will then reply with its RSSI value.

Arduino GPRS shield only showing first character of SMS via serial monitor (AT+CMGR Not working)

I am interfacing a seeedstudio GPRS shield for my arduino UNO via the serial monitor Arduino window, and some writing directly echo'd to the tty (I am using Linux)
I am able to interface with it properly in the regards of sending text messages and even receiving them, however when I run the command to read the messages (Knowing it's ID) I am only returned the first character of the message, as such:
+CMGR: "REC READ","MYPHONENUMBERHERE","","13/10/15,21:45:44-40"
H
The full message was "Hmmm" and the only thing showing is the "H"
The exact command run is as follows:
AT+CMGR=3
Also, interestingly enough, when I run
AT+CMGL="ALL"
I do appear to get every message
+CMGL: 2,"REC READ","+1xxxxxxxxxx","","13/10/15,21:35:51-40"
+CMGL: 3,"REC READ","+1xxxxxxxxxx","","13/10/15,21:45:44-40"
+CMGL: 4,"REC READ","+1xxxxxxxxxx","","13/10/16,06:08:24-40"
ALSO, the SIM was obtained through AT&T's GoPhone service, and is properly activated with the SIM900 Module on the GPRS shield, and as mentioned, can send text messages fine, but getting them to show up correctly is broken.
The shield I am using is found here:
www.seeedstudio.com/wiki/GPRS_Shield_V1.0
I had the same issue and finally found there was a maximum receive buffer size of 64 set in the SoftwareSerial.h include file.
I found the following line:
#define _SS_MAX_RX_BUFF 64 // RX buffer size
and changed it to:
#define _SS_MAX_RX_BUFF 128 // RX buffer size
Then I could see the whole message.
The include file SoftwareSerial.h can be found in the Arduino/libraries/SoftwareSerial directory. For Arduino 1.0.5, which I am running under Windows.
On my MAC (which is running Arduino 1.5.4) I found the file: SoftwareSerial_Class.h contains the old SoftwareSerial.h code. Haven't tested this one yet!
Post back and let me know how you go.
I change it to:
#define _SS_MAX_RX_BUFF 256 // RX buffer size
because the message could be 160 character long.
!! NOTE the number must has only this values: 64, 128, 256, 512(?) and so !!

Resources