How to get list of xbee devices in network using digi xbee Python - radio

I have a xbee code running which has a scheduler scheduled to run every 1min. This scheduler queries the network and gets the xbee devices which are online. Below is the code:
def search_devices_in_nw():
log_debug.error("Discovery process starting....")
net = device.get_network()
net.start_discovery_process(deep=True, n_deep_scans=1)
while net.is_discovery_running():
time.sleep(0.5)
active_nodes = net.get_devices()
print(active_nodes)
schedule.every(1).minutes.do(search_devices_in_nw)
while device.is_open():
schedule.run_pending()
I have two devices in my xbee network and running this code, gives 2 mac address which is correct. But if I put one of the xbee device offline, it still gives result as 2 mac address online which is incorrect.
If I stop my code and restart it, then it shows 1 mac address online. I am not sure why the code is not working fine. Can anyone please help me in this. Please help. Thanks
Documentation page: https://xbplib.readthedocs.io/en/latest/user_doc/discovering_the_xbee_network.html#discovernetwork

Per the documentation, "All discovered XBee nodes are stored in the XBeeNetwork instance."
But you can also clear the list of nodes with the clear() method on the XBeeNetwork object before initiating a new discovery:
[...]
# Instantiate a local XBee object.
xbee = XBeeDevice(...)
[...]
# Get the XBee network object from the local XBee.
xnet = xbee.get_network()
# Discover XBee devices in the network and add them to the list of nodes.
[...]
# Clear the list of nodes.
xnet.clear()
[...]

Related

Is there any way to stop a particular CAN message coming from another real ECU to DUT (real ECU) on the bus through CAPL scripting?

I am trying to create a CAPL script (test module) to automate my testcases. In the system (test setup) we have all the real ECU's connected with Device/ECU under test. I have came across this function ILDisableMsg(messageName)/testDisableMsg(msgId) in CAPL which will block/stop a particular message from simulated node(IL node). Similarly, is there any way to block/stop a particular message from real ECU to DUT receiving it through CAPL script?
For your case, the correct way is to stop the physical connection with the real ECU. You could use:
TestSetEcuOffline: Used to ECU Disconnect from the bus
TestSetEcuOnline : Used to ECU Connect to the bus
But, this will stop the whole communication with the real CAN bus channel.
To avoid such situation, try to stop sending internal signals that map your can massage from the SW side.
Don´t forget also to either stop IL block or remove the simulated massage from the configuration!

Couchbase Java SDK times out with BUCKET_NOT_AVAILABLE

I am doing a lookup operation Couchbase Java SDK 3.0.9 which looks like this:
// Set up
bucket = cluster.bucket("my_bucket")
collection = bucket.defaultCollection()
// Look up operation
val specs = listOf(LookupInSpecStandard.get("hash"))
collection.lookupIn(id, specs)
The error I get is BUCKET_NOT_AVAILABLE. Here are is the full message:
com.couchbase.client.core.error.UnambiguousTimeoutException: SubdocGetRequest, Reason: TIMEOUT {"cancelled":true,"completed":true,"coreId":"0xdb7f8e4800000003","idempotent":true,"reason":"TIMEOUT","requestId":608806,"requestType":"SubdocGetRequest","retried":39,"retryReasons":["BUCKET_NOT_AVAILABLE"],"service":{"bucket":"export","collection":"_default","documentId":"export:main","opaque":"0xcfefb","scope":"_default","type":"kv"},"timeoutMs":15000,"timings":{"totalMicros":15008977}}
The strange part is that this code hasn't been touched for months and the lookup broke out of a sudden. The CB cluster is working fine. Its version is
Enterprise Edition 6.5.1 build 6299.
Do you have any ideas what might have gone wrong?
Note that in Couchbase Java SDK 3.x, the Cluster::bucket method returns instantly, and continues opening a bucket in the background. So the first operation you perform - a lookupIn here - needs to wait for that resource opening to complete before it can proceed. It looks like it took a little longer to access the Couchbase bucket than usual and you got a timeout.
I recommend using the Bucket::waitUntilReady method after opening a bucket, to block until the resource opening is complete:
bucket = cluster.bucket("my_bucket")
bucket.waitUntilReady(Duration.ofMinutes(1));
This problem can occur because of firewall. You need to allow these ports.
Client-to-node
Unencrypted: 8091-8097, 9140 [3], 11210
Encrypted: 11207, 18091-18095, 18096, 18097
You can check more from below
https://docs.couchbase.com/server/current/install/install-ports.html#_footnotedef_2

Cannot send commands to remote machine using ssh2-python package

Problem
Hello my problem is that I want to use the ssh2-python package to remotely read a a bunch of files, but I can't seem to send commands to the remote host machine.
Originally I started with the paramiko package and I did get that to work, but I am dealing with a lot of large memory files (which is why I can't bring them to the local machine) and it is a bit too slow. I am currently running Python 3.6.3 & ssh2-python 0.18.0.post1 and have tried changing versions of ssh2-python, but it didn't help.
Code
import socket
from ssh2.session import Session
host_ip=socket.gethostbyname('hostname')
sock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host_ip,22))
session=Session()
session.handshake(sock)
print(session.userauth_list('username'))
session.userauth_password('username','password')
channel=session.open_session()
channel.execute('echo Hello')
Code Prints the Following
0
['publickey', 'gssapi-keyex', 'gssapi-with-mic', 'password']
0
0
Expectation/Thoughts
I expected the code to print Hello, but instead it just printed 0. It also printed 0 after the handshake and after the call to the authentication method and I have no idea why. It seems like I am in contact with the remote machine as it did print out which authentications it would take, but it doesn't appear to me that I am actually logged in and can do anything. I would really like to use this package as from what I read online it is significantly faster paramiko, (alternatives would be good to) but I can't seem to figure out what is going on here.
Please help and thanks in advance!
You may in fact be connected and executing commands, but channel.execute('ls') returns '0' (it's exit/status code).
If you want to read your response from the server:
channel.execute('echo Hello')
size, data = channel.read()
while size:
size, dt = channel.read()
data += dt
print(data.decode())
The API documentation for ssh2-python is rather sparse, but the examples should get you through some of the basics: https://github.com/ParallelSSH/ssh2-python/tree/master/examples
A complete version of the above is in example_echo.py

STM32 StdPeriph library USART example

I downloaded Stdperiph library and i want to make USART example run on STM32F4 - Discovery. I chose STM32F40_41xxx workplace, added stm32f324x7i.c file and compiled without any errors.
Issue is that I cant receive expected message in my terminal (using Hercules), also when I check RxBuffer it is receiving some bytes but not that I sent.
I checked baudrate, wordlength, parity several times. Do you have any idea what could I do wrong?
USART conf:
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_2;
USART_InitStructure.USART_Parity = USART_Parity_Odd;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
STM_EVAL_COMInit(COM1, &USART_InitStructure);
Thank you.
First of all if you want to use hihg level abstraction libraries stop using obsolete SPL and start using HAL. Install the Cube. Generate the code - import into your favorite IDE and compile. Should work.
Your code does not show anything as USART clock may be net enabled as well as GPIOs. GPIOs may be configured wrong way. You system and peripheral clock may have wrong frequency. There are many more potential problems.

Using a Webpage to Control Robot Arm Written in Linux

Firstly I am no longer a student and currently working on a favour for a friend. I am making a website which has a live video feed of a robotic arm and a set off buttons that will allow users with the basic interaction of the robotic arm.
I have setup the website and live video feed. I do have a 4 second delay using flash media encoder and flash server 4.5. Have any suggestions in reducing the delay time?
I have done the python code required for the maplin robotic arm and now I am stuck and not sure how to link my python code with a webpage interface? Can anyone that has done this before provide with code that I could edit and learn from..
Python Code
import usb.core
import usb.util
import sys
import time
# This program is intended to control a robotic arm via USB from Linux
# The code is written in Python by Neil Polwart (c) 2011
# It is a work in progress and will improved!
# locate the device device
dev = usb.core.find(idVendor=0x1267, idProduct=0x0000)
# assigns the device to the handle "dev"
# can check the device is visible to Linux with command line command lsusb
# which should report a device with the above vendor and id codes.
# was it found?
if dev is None:
raise ValueError('Device not found') # if device not found report an error
# set the active configuration
dev.set_configuration()
# as no arguments, the first configuration will be the active one
# note as commands are sent to device as commands not data streams
# no need to define the endpoint
# defines the command packet to send
datapack=0x80,0,0
# change this packet to make different moves.
# first byte defines most of the movements, second byte shoulder rotation, third byte light
# command structure in more detail:
# http://notbrainsurgery.livejournal.com/38622.html?view=93150#t93150
print "requested move",datapack # reports the requested movement to the user
# send the command
bytesout=dev.ctrl_transfer(0x40, 6, 0x100, 0, datapack, 1000)
# outputs the command to the USB device, using the ctrl_transfer method
# 0x40, 6, 0x100, 0 defines the details of the write - bRequestType, bRequest, wValue, wIndex
# datapack is our command (3 bytes)
# the final value is a timeout (in ms) which is optional
# bytesout = the number of bytes written (i.e. 3 if successful)
print "Written :",bytesout,"bytes" # confirm to user that data was sent OK
# wait for a defined period
time.sleep(1) # waits for 1 second whilst motors move.
# now STOP the motors
datapack=0,0,0
bytesout=dev.ctrl_transfer(0x40, 6, 0x100, 0, datapack, 1000)
if bytesout == 3: print "Motors stopped"
So I need to find a way to edit the datapack line via a website interface. Any help is appreciated! I am using a Windows 7 setup but do have access to vmware
I'd set up an Apache server with mod_python and create a handler that imports your script and runs the necessary code. You can set up an AJAX script in JavaScript (with or without jQuery). Every time you want to run the Python script, a request needs to be made to the server. You can pass any information back and forth as needed via the HTTP.
Here's a good tutorial for Python and the CGI Module.