I'm playing arround with a Raspberry pi zero but it has some issues powering my WIFI dongle.
Nov 21 21:42:49 raspberrypi kernel: [ 456.466068] usb 1-1.1: rejected 1 configuration due to insufficient available bus power
It works, but it requires some manual labour to to turn it on:
echo 1 > /sys/bus/usb/devices/1-1.1/bConfigurationValue
In my case, this enables the device and then all is well. However, I need to repeat this step after each boot (tried init script, no luck yet).
My question is how to solve this problem. Preferably i'd just like to disable the power check (if possible) and just have the kernel configure the device.
Is this possibe/is there a better solution?
I had a similar problem (my router sometimes acted weird and my Pi didn't reconnect) and I use a script that checks every minute if the Pi has a wifi connection, if not it "reboots the wifi". (Got it from this tutorial http://alexba.in/blog/2015/01/14/automatically-reconnecting-wifi-on-a-raspberrypi/)
#!/bin/bash
# The IP for the server you wish to ping (8.8.8.8 is a public Google DNS server)
SERVER=8.8.8.8
# Only send two pings, sending output to /dev/null
ping -c2 ${SERVER} > /dev/null
# If the return code from ping ($?) is not 0 (meaning there was an error)
if [ $? != 0 ]
then
# Restart the wireless interface
ifdown --force wlan0
ifup wlan0
fi
Although it probably is not the most elegant solution you could just follow this tutorial and replace
ifdown --force wlan0
ifup wlan0
with this I guess:
echo 1 > /sys/bus/usb/devices/1-1.1/bConfigurationValue
But since you say that you say that you just need to run this script on boot and it works until you power the Pi back off again making a simple python script like
import os
os.system("echo 1 > /sys/bus/usb/devices/1-1.1/bConfigurationValue")
and making sure it starts on boot by adding this line in the /etc/rc.local file just above the exit 0 in that file:
sudo python /path/to/the/python/script/this_script.py
This should do the trick although I'm pretty sure the Pi has a good reason disabling your Wifi dongle (I'm pretty sure you could 'burn out' your Pi by using to much current if there was no protection). What Wifi dongle are you using and what are your powering you Pi with? I'm sorry for my not so clear answer, I'm just starting to get into the Pi but I hope I was at least of some help.
Related
I have a Raspberry Pi with a 4G USB dongle connected to it for internet access. Everything works on power-up, everything auto-connects and connectivity is established.
In fact if I leave the Raspberry Pi on my desk powered up it stays connected through the 4G dongle for weeks without any issues.
As soon as I leave my mobile cell area, connectivity drops out and does not recover. I also want to be able to unplug the USB 4G dongle and reconnect it and have the cell link auto recover. I am using USB-Modeswitch and wvdial.
Is there anyway I can get the 4G dongle to auto recover?
Thanks for reading.
Brodes.
OK I think I have found the solution I was looking for....
I created this script that sends 5 pings to the other end of a VPN tunnel. If the pings fail then the Raspberry Pi reboots.
#!/bin/bash
# This script checks for an active Internet connection by pinging.
# If the pings fail, it will reset the USB modem dongle.
ping -c5 10.8.0.1
let a=$?
if [ "$a" != "0" ]; then
/sbin/shutdown -r now Connection lost, rebooting...
fi
Then I created a cronjob to run this script every 2 minutes.
If anyone has a better idea please let me know.
Cheers,
Brodes.
I am running a setup of 4 ESP32 which are connected to a PI through serial connections. Is there a way to statically bind all of the ESPs, so the port order after every boot doesn't matter?
It also has to be ID unspecific, since I'm running several similar setups and the code should fit all.
Also, in case of a replacement, I just want the system to know that there is the same device on the same port.
I'm sorry if I wrote it confusing, but generally, I want the ESPs to be replaceable, while the port describes the function of the device.
Thanks guys and happy coding
The only practical approach is ID based, sorry. USB devices are created in the same order they are initialized, so no guarantees whatsoever. If it helps, here's an udev rule which creates symlinks from the serial number of the Silabs USB-serial chip, e.g. /dev/EDK-d80d38b81e. Tested with DevKitC and LOLIN32 boards.
# udev rules for the Espressif ESP32-DevKitC and Wemos LOLIN32 dev boards to
# allocate symlinks with fixed names for each device using its serial number.
# CP2102N/CP2104N with idVendor=10c4, idProduct=ea60
#
# Instructions:
# 1. Copy udev rules and restart daemon:
# $ sudo ln -s "$PWD/70-cp210xn_ESP32-DevKitC.rules" /etc/udev/rules.d/ && sudo systemctl restart udev
# 2. Disconnect and connect the board to USB
# Espressif ESP32-DevKitC with CP2102N.
# Sample serial in chip is "7063b99e4b74ea11b6f52208cf25bb41" where only first
# 10 chars seem to be unique. We cut the serial down to those and create a
# symlink from the result, e.g. "/dev/EDK-7063b99e4b"
SUBSYSTEMS=="usb", KERNEL=="ttyUSB*", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ATTRS{manufacturer}=="Silicon Labs", ATTRS{product}=="CP2102N USB to UART Bridge Controller", PROGRAM="/usr/bin/awk -- 'BEGIN { print substr(\"$attr{serial}\",1,10) }'" SYMLINK+="EDK-%c", GROUP="dialout", MODE="0660"
# Wemos LOLIN32 with CP2104N, sample serial in chip is "01DFA32C".
# We create a symlink "EDK-01DFA32C" (cropping to first 10 chars just in case).
SUBSYSTEMS=="usb", KERNEL=="ttyUSB*", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", ATTRS{manufacturer}=="Silicon Labs", ATTRS{product}=="CP2104 USB to UART Bridge Controller", PROGRAM="/usr/bin/awk -- 'BEGIN { print substr(\"$attr{serial}\",1,10) }'" SYMLINK+="EDK-%c", GROUP="dialout", MODE="0660"
I had a similar issue, where I needed to statically bind physical USB ports to devices, in my case they are cheap serial/USB converters and they don't have a unique ID, so the only way to identify them was using physical port mapping.
I solved creating udev rules with aliases, like this:
SUBSYSTEM=="tty",KERNELS=="2-2:1.0",SYMLINK+="device1"
SUBSYSTEM=="tty",KERNELS=="2-3:1.0",SYMLINK+="device2"
Now I open the connection with the devices using the symlinks. In this way as long as you don't swap connectors, each device will always have the same symlink.
Unfortunately, the Raspberry Pi (don't know about linux in general) is reassigning the USB ports after each boot or when connecting/disconnecting devices. So the serial port numbers change more or less randomly. You need some other way of identifying which device is which. Probably the best method is to use unused pins for identifying the device and query the device id from the host at startup, so you know which ESP32 is connected on which port.
I am using fauxmo to have Alexa trigger a script on a Raspberry Pi, which then triggers a BroadLink RM hub to send out IR and RF signals for my home theatre.
This has worked beautifully for a year or two, and yesterday it stopped. I did not touch anything, I swear!
I found out that fauxmo does no longer receive Alexa discovery requests.
When I ask Alexa (voice/web/app) to discover devices, it sends out SSDP M-SEARCH requests to 239.255.255.250 1900. I can verify this using Wireshark on a Windows laptop.
However, these requests do not seem to get to the Raspberry Pi anymore. I have tried with two Raspberries. Confirmed they are on they same WiFi network, which is Google Wifi (and confirmed Upnp is enabled). And I powercycled Alexa and Google Wifi.
I also sent M-SEARCH requests locally on the Raspberry Pi, and those are received.
window 1:
sudo tcpdump -n udp dst port 1900 -A
window 2 (on same Pi):
echo -e "M-SEARCH\r\nurn:Belkin:device:**" | nc.traditional -q 1 -u 239.255.255.250 1900
window 1 result:
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on wlan0, link-type EN10MB (Ethernet), capture size 262144 bytes
02:06:41.485902 IP 192.168.86.247.45796 > 239.255.255.250.1900: UDP, length 31
E..;+.#...FO..V........l.'m.M-SEARCH
urn:Belkin:device:**
However, if I do this on 2 Pi's (window 1 on one, window 2 on the other), the request is not received. Actually, I also tried with another Ubuntu machine, so it's not specific to Pi.
I thought that it could be a general network issue, but then I would not see the Alexa requests on my Windows laptop.
I am at a loss - I did not make any code or configuration changes (actually it worked at the beginning of a movie "Alexa turn projector on", and it did not work after the end of the movie "Alexa turn projector off").
Wiring the Pi to the Google WiFi pod worked, I posted this at Google WiFi instead - https://support.google.com/wifi/thread/13904262
I am trying to connect a Temp and Humi probe Adafruit AM2315 and it seams that the only thing I need to do is to get i2c running on my Pi2. I can't seams to find the proper instructions or command line to get it config and running ? Can someone help ?
did you connect it directly to the RPi2 I2C pins, or did you use the 10KOhm resistors too..?
It seems it needs two rapid connections to wake up first, before starting to send commands, see here:
http://raspberrypihobbyist.blogspot.it/2015/02/using-am2315-temperaturehumidity-sensor.html
David
I have an application that does a lot of binary data loading. I've encountered scenarios where an unstable 3G connection may intermittently cut out during the loading of some of this binary data, causing issues.
Is there any way, using the simulator or otherwise, to test for low-bandwidth/unstable connection scenarios?
I seem to recall Adobe Flash having bandwidth simulators in their test suite.
You can accomplish this by creating a wireless network on your Mac using Internet Sharing, degrading that interface using firewall rules, and connecting your iPhone to that network. This will actually work to debug any device that connects to a wireless network.
Using this technique, you can simulate extremely meager, lossy, or latent networks.
I use this technique instead of Apple's official Network Link Conditioner for a couple reasons:
Throttling can be applied only to specific connected devices, rather than affecting your development machine's network connection.
It can be scripted to simulate rapidly changing or "bursty" networks.
Unlike the Network Link Conditioner built into iOS, you can change the settings while your application remains in the foreground.
This uses ipfw's dummeynet feature. ipfw is technically deprecated in modern versions of OS X, but it still works fine. Unfortunately, pf (the replacement) doesn't yet support arbitrary packet delays. I'll update this answer if something changes.
Creating an awful Wi-Fi network
Plug into Ethernet if you aren't already.
Enable Internet Sharing in the Sharing pane of System Preferences. Choose to "Share your connection from: Ethernet" and check "Wi-Fi".
Get your phone connected to the network you just created and make sure you can browse the web.
Tell Mac OS's built-in firewall (ipfw) to ensure packets that have latency applied (pass through the "dummynet" in ipfw parlance) are still routed through the normal rules. This allows Internet Sharing to continue working:
phil#Nebula ~$ sudo sysctl -w net.inet.ip.fw.one_pass=0
net.inet.ip.fw.one_pass: 0 -> 0
Configure the low-quality pipe through which your iPhone's traffic will pass (14Kb/s throughput with 1% packet loss):
phil#Nebula ~$ sudo ipfw pipe 1 config bw 14KB/s
phil#Nebula ~$ sudo ipfw pipe 1 config plr 0.01
The next step varies depending on whether you're on Mountain Lion or below, or Mavericks.
For Mountain Lion (10.8) or below:
Route packets into the pipe, but only for traffic over your AirPort interface:
phil#Nebula ~$ sudo ipfw add 10 pipe 1 ip from any to any via en1
00010 pipe 1 ip from any to any via en1
Important: If you're using an Air or new MacBook Pro without a physical ethernet port, your AirPort interface will likely be called en0. Replace en1 with en0 above if that's the case.
For Mavericks (10.9):
Check the output of ifconfig and look for the bridge interface created by Internet Sharing:
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether xx:xx:xx:xx:xx:xx
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en4 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 6 priority 0 path cost 0
nd6 options=1<PERFORMNUD>
media: <unknown type>
status: inactive
bridge100: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=3<RXCSUM,TXCSUM>
ether xx:xx:xx:xx:xx:xx
inet 192.168.2.1 netmask 0xffffff00 broadcast 192.168.2.255
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en1 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 5 priority 0 path cost 0
media: autoselect
status: active
You want the bridge interface that has an IP address; in most cases, it will be bridge100.
Route packets into the pipe, but only for traffic over the bridge interface:
phil#Nebula ~$ sudo ipfw add 10 pipe 1 ip from any to any via bridge100
00010 pipe 1 ip from any to any via bridge100
Change bridge100 if it has a different name on your system.
Simulating a changing network
You can change the values 14KB/s and 0.01 in step 5 above to simulate different types of networks. You can also specify config delay 1000 to introduce a 1000ms delay. See the manpage for more options.
You can continue to reconfigure the pipe after adding the rule for it. For instance, to simulate nearing the edge of cellular coverage, issue this command while your app is running and connected (95% packet loss):
phil#Nebula ~$ sudo ipfw pipe 1 config plr 0.95
There is no need to run sudo ipfw add 10 … again after reconfiguring the pipe. You can script these changes to simulate an extremely dynamic network environment.
Cleaning up
You can issue sudo ipfw delete 10 to put everything back to normal, or just reboot.
Here is a great script I've used on OS X to throttle connection speed, or just turn it off, for any domain you want. I wish I could remember where I got it from to give credit.
Save the code to a file on your machine and name it "throttling". Then to run, just enter the below in terminal, and select from one of these speeds: [full|fast|medium|slow|wwdc|off].
"./throttling medium"
If you have the script set up to throttle localhost:3000 and stackoverflow.com, then loading up a page from either of those domains in your browser (or iphone simulator or whatever) will respond slower and load files slower. It's been really great for testing iphone connectivity bugs.
http://gist.github.com/499177
You could test a number of things if you turn 3G off and connect to wifi.
Log into your router and rate limit the mac address of your iphone. (to test slow connections)
Kill the power to the wifi when in the middle of downloading data
Reboot the wifi router when downloading so the phone has connection, loses it, and gets it again. ( to test different scenarios )
Happy Coding!
I read of someone testing with their iPhone connected by USB cable and the phone wrapped in aluminum foil to get the cellular signal reduced. You can turn off WiFi and 3G and just have Edge and then attenuate it with foil. Sounds crude but...
You could also use an iPhone 4 and hold in your hand to short the two antennas together ;-)
Chrome 38 includes network emulation in the device emulation settings. You can select from Offline, GPRS, EDGE, 3G, DSL and WiFi. Also emulates increased latency.
It's not as accurate as testing on a real device but it's much quicker to set up.
Well, low bandwidth is simple: turn off Wifi, turn off 3G. Cutting connection is also simple: turn on wifi, get connected, power off your wifi access point.
I guess you could connect to a Mac (if you had one) setup as a WiFi base station (ad-hoc network). Then on the Mac set up a "dummynet" bandwidth limit and/or high packet loss filter.
That's what I do to simulate the slower higher-latency DSL lines I am making software to setup for Macs.
On the iPhone you can't. One way would be to share your computer WIFI connection to your iPhone but to slow it down using a special application.
This blog post describes some approaches for that:
http://blog.aptivate.org/2010/01/23/make-sure-your-apps-work-in-the-field/