<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>shell over NUS (NUS shell transport) not working as expected</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100902/shell-over-nus-nus-shell-transport-not-working-as-expected</link><description>I have adapted the shell over NUS example into some code we have ourself. The code we have have so far used physical UART as a shell interface. I can see that the Bluetooth connection is also reported as a backend, but I don&amp;#39;t get any response on shell</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 30 Nov 2023 14:46:58 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100902/shell-over-nus-nus-shell-transport-not-working-as-expected" /><item><title>RE: shell over NUS (NUS shell transport) not working as expected</title><link>https://devzone.nordicsemi.com/thread/458342?ContentTypeID=1</link><pubDate>Thu, 30 Nov 2023 14:46:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4fef7602-8973-484d-b9e0-a62df9aae4a9</guid><dc:creator>frankbuss</dc:creator><description>&lt;p&gt;I had the same problem. For Linux, there are tools from Nordic to solve it, see the documentation:&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/shell/shell_bt_nus.html"&gt;developer.nordicsemi.com/.../shell_bt_nus.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;But I wrote a simple&amp;nbsp;one file Python script to have just a terminal to the NUS shell. It is a bit slow, because of the polling, but otherwise works well, including ANSI color, tab-completion etc.:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="python"&gt;#!/usr/bin/env python3

# installation requirement:
# pip3 install bluepy
#
# first connect a USB bluetooth adapter. &amp;quot;hcitool dev&amp;quot; should show it:
#
# $ hcitool dev
# Devices:
#         hci0    18:4F:32:F2:16:22
#
# If not, then check, if the USB device is recognized at all:
#
# $ lsusb
# Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
# Bus 001 Device 019: ID 0a5c:21e8 Broadcom Corp. BCM20702A0 Bluetooth 4.0
# ...
#
# If it doesn&amp;#39;t get detected, try another USB adapter.
#
# If detected, then maybe first start it:
#
# sudo hciconfig hci0 up
#
# Sometimes the Bluetooth stack gets stuck, and even a `hcitool lescan`
# doesn&amp;#39;t work anymore, or you get an error like this:
# bluepy.btle.BTLEManagementError: Failed to execute management command &amp;#39;scanend&amp;#39; (code: 11, error: Rejected)
# In this case, restart the interface like this:
#
# sudo hciconfig hci0 down
# sudo hciconfig hci0 up
#
# If you have more than one USB bluetooth adapter, try hci1 etc.
#
# Then start the peripheral, and search for the key fob:
#
# $ sudo hcitool lescan
# LE Scan ...
# E9:56:3D:BF:59:3E FOOBAR
# ...
#
# Important: if you have more than one bluetooth adapter, then old Bluetooth 4 adapter
# might see it, too, but it won&amp;#39;t work with it. Then as described above, use the right
# adapter with hciconfig.
# 
# Finally start the NUS script:
#
# $ ./nus.py E9:56:3D:BF:59:3E
#
# the output should look like this:
# connected
#
# Then you can use it like a terminal, tab-completion works, too.

import struct
from bluepy.btle import *
import sys
import time
import atexit

import sys, termios
from select import select

if len(sys.argv) != 2:
	print(&amp;quot;usage: python nus.py bluetooth-address&amp;quot;)
	exit()

# save the terminal settings
fd = sys.stdin.fileno()
new_term = termios.tcgetattr(fd)
old_term = termios.tcgetattr(fd)

# new terminal setting unbuffered
new_term[3] = (new_term[3] &amp;amp; ~termios.ICANON &amp;amp; ~termios.ECHO)
termios.tcsetattr(fd, termios.TCSAFLUSH, new_term)

def getch():
    return sys.stdin.read(1)

def kbhit():
    dr,dw,de = select([sys.stdin], [], [], 0)
    return len(dr)&amp;gt;0

# at script exit, restore termios settings
def restore():
    termios.tcsetattr(fd, termios.TCSAFLUSH, old_term)
    print()
atexit.register(restore)

# callback class for handling Mobee messages
class MyDelegate(DefaultDelegate):
    def __init__(self):
        DefaultDelegate.__init__(self)

    def handleNotification(self, cHandle, data):
        sys.stdout.buffer.write(data)
        sys.stdout.flush()

# connect to device
per = Peripheral(sys.argv[1], &amp;quot;random&amp;quot;)
print(&amp;quot;connected&amp;quot;)

while True:
    try:
        # set callback for notifications
        per.setDelegate(MyDelegate())

        # enable notification
        setup_data = b&amp;quot;\x01\x00&amp;quot;
        notify = per.getCharacteristics(uuid=&amp;#39;6e400003-b5a3-f393-e0a9-e50e24dcca9e&amp;#39;)[0]
        notify_handle = notify.getHandle() + 1
        per.writeCharacteristic(notify_handle, setup_data, withResponse=True)
        
        # get send characteristics
        c = per.getCharacteristics(uuid=&amp;#39;6e400002-b5a3-f393-e0a9-e50e24dcca9e&amp;#39;)[0]
        
        # wait for answer
        while True:
            if per.waitForNotifications(0.0001) or True:
                if kbhit():
                    ch = getch()
                    c.write(ch.encode(&amp;#39;latin-1&amp;#39;))
                continue
    except KeyboardInterrupt:
        sys.exit(0)
    finally:
        per.disconnect()
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: shell over NUS (NUS shell transport) not working as expected</title><link>https://devzone.nordicsemi.com/thread/433545?ContentTypeID=1</link><pubDate>Wed, 28 Jun 2023 19:47:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2a6f43e4-863c-4d85-a510-680ebf413fcc</guid><dc:creator>Geir Strand</dc:creator><description>&lt;p&gt;Sometimes the simplest thing is creating problem. Problem lies (partially) between keyboard and chair:&amp;nbsp;&lt;br /&gt;I used the nRF Toolbox on the phone to try out the code.&amp;nbsp;&lt;br /&gt;Every time I tried to transmit something I saw that it got transmitted, and I got the characters echoed back. But nothing happened.&lt;br /&gt;The problem is that when you send something from the nRF Toolbox (at least on iOS), the carrier-return/line-feed is not sent! This I discovered when debugging and seeing that only 4 characters got sent when it wrote &amp;quot;help&amp;quot; and hit return.&lt;br /&gt;Making a macro did change all this.&amp;nbsp;&lt;br /&gt;An idea for the application team at Nordic: Make the serial terminal support Bluetooth LE serial port. There are cross-platform libraries for bluetooth (I don&amp;#39;t know if it exists for electra, but python and others have now cross-platform libraries).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: shell over NUS (NUS shell transport) not working as expected</title><link>https://devzone.nordicsemi.com/thread/431516?ContentTypeID=1</link><pubDate>Fri, 16 Jun 2023 13:37:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7358f856-2ea3-4080-9eb4-986e5723f7a8</guid><dc:creator>Einarh</dc:creator><description>&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;Does the NUS shell example by itself work as intended?&lt;/p&gt;
&lt;p&gt;If so, have you looked at the configs used in that sample?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>