I'm trying to create a clock in python that runs in minecraft pi. It's functional apart from the fact that each minute, it updates the numbers on minecraft another half second later than it should. I'm pretty sure that python knows it's changed, it just hasn't sent the message to minecraft to change anything yet - this is very bad in the long run, as you can imagine! I honestly don't know what's causing the lag - is it the limitations of the Raspberry pi? I've checked my code for any rogue 'sleeps' and I can't find any. Any suggestions as to why it's gone wrong?
http://pastebin.com/XfUk5TmH
PS - it's a very large program - the better part of 1000 lines, so be warned..
Related
I have a connection to a websocket server that some python code runs, and after some time (doesn't happen right away), it begins to send massive amounts of data "out" as shown in the screenshot. It's aroudn 4.8 megabytes per second on average. Prior to it starting to do this, it sends maybe 30 kb/s in what I assume is normal operation.
It can add up to hundreds of gigabytes in a day or two, depending on network speeds.
If I kill the original python process that was running and using the websocket client (kill -9 1234), it does not stop the traffic. I'm using Little Snitch for MacOS to obtain this information, and I feel like there is more info available under the surface I should be able to get to find out what's sending/receiving this data and what the data is.
If I terminate iTerm itself, the traffic still doesn't stop. If I launch regular Mac Terminal and do a ps aux | grep iterm I get nothing, and I get the same 4 processes shown in the screen shot if I do a | grep python...
This kind of throughput is really high, it's enough to be streaming my screen, uploading my entire hard drive, etc. or maybe it's just a code bug and it's sending garbage.
The only other relevant things I can think of adding right now are:
This is a brand new Macbook Pro M1 chip 13"
According to MenuMeters (resource monitor) there have been 16 billion page faults.. no idea if that's normal.
I have tried testing this by rebooting and just "not launching" my python code to get the websocket data, and basically I can wait a while and nothing seems to happen, so I think it's only happened after I launch the connection, and then I wait a while.
Sorry, I wish I knew how to get more relevant information for you, but if anyone has a good idea of how I can generate better logs or dig deeper I'd appreciate it.
screenshot of little snitch traffic
Sorry, I wish I knew how to get more relevant information for you, but
if anyone has a good idea of how I can generate better logs or dig
deeper I'd appreciate it.
Wireshark will allow you to track all connections and check what is inside the packets.
I'm asking this question because I've noticed that a lot of (if not all) discord bots go offline every few hours, then come back 2 seconds later. After making my own bot, it does the exact same thing (and it's only in 4 servers). Every few hours, it goes offline for 2 seconds then comes back. Does anyone have an explanation as to why this happens?
Debugging
When the problem occurs, it also triggers on_ready(), which seems to me to mean that it isn't discord, but the client.
Other Information
I am using discord.py-rewrite library, but I've seen this happen with the discord.js library as well
This happens in active servers
Unless most bot developers make the same mistake, this is not a problem with my code.
This is not a pressing issue for me. I am just mostly curious why and am not necessarily looking for a solution, though I would appreciate it if you had one.
It could be possible that the Raspberry Pi loses connection to the discord client if it's connected wirelessly to the internet. Mine does the same for other servers unless it's connected through ethernet.
Background: I have a TCP Socket python script set up on a Raspberry Pi 4 to speak with an off-network machine. The machine has commands set up that I send it a request over the socket essentially querying "What is the value of A?" and the machine response is the value of A. While I am not super familiar with the coding of the machine, my understanding is that when queried in this way, it prints out the value. I am receiving that data through the socket by simply putting a socket.sendall("What is the value of A") followed immediately by a socket.recv(SIZE). My analogy is its like throwing a ball against the wall with one hand, and catching it with the other. The connection is made with an Ethernet cable approximately 100ft long.
Problem: I can query across this socket quite a bit, up to the point that I can send 60 entry arrays back and forth between 5-10 times, but eventually, the connection closes up. I'm not quite sure why this is. It gets to the point where I have to unplug everything, close out all the sockets, and just give it some time before trying again. While it may not be clear to diagnose the problem without fully understanding the machine (which I can't really give more information about), I am leaning towards using threading to run the two processes independent: one thread to query, one thread to receive. My guess would be that the recv() misses the proverbial ball, and then sits waiting to hear back from the machine, but the machine never talks again because the code is just left to wait. I don't have a lot of experience with threading, and therefore would appreciate some suggestions. Another thought is that the Ethernet cable is too long for the Pi to handle pushing that much data across. This feels more naive, but I am not a network engineer and therefore don't claim to fully understand that process.
Thanks in advance, feel free to ask any clarifying questions.
I have my circuit hooked up correctly. It's a simple python script running on my RPi 2.
I've done this countless times and I decided to mess around with it today since it's been a while but I know I have the circuit correct and if I hook it up with my 5V, it will stay lit. But if I connect it to a GPIO and use my python script, the LED blinks for a random amount of times (usually for about 3-5 seconds) and then it just stops.
I've tested it with a multimeter and the jumper wires are all working. I tested continuity on the GPIO pin w/ GND and it would beep for as many times as it would make the LED blink and then continuity would stop.
My script continues to run and if I print something during the loop, it will continue to loop.
Everything is pointing to my RPi being broken but I've done nothing to it to break it and it's been sitting quietly since I've last used it.
Does anyone have any insight into this? This is really frustrating because this is just a simple script that should not have any issues.
Occasionally, when I messed with the wires, the LED would momentarily flash but it would be a very weak flash and then nothing. I've also tried to connect it directly to the RPi and skipping the extra wires and it still doesn't work. It seems like the GPIO pin is messed up but I've tried it with multiple GPIO pins.
When I try with other pins (currently using GPIO-07), it will tell me that the pin is already in use, even though it is most definitely not.
I'm also using the same script that I have saved on my Pi from a long time ago. 0 changes made to it but it's no longer looping infinitely, it stops after 4 seconds.
this is my first post on stack overflow yet I use it all the time to solve my many programming issues. So first off, thank you for any help that is given.
I have been given a task by my advisor to get HC-05 sending and receiving serial comms with python and I am at my wits end on the final part of getting it up and running. I have searched everything I possibly can and have not yet found the answer, or even a similar issue. I have the comms working somewhat well. My baud rate is set at 115200 and have that matched in python serial. I am using an Arduino to gather values from sensors on a robot, send the values to python over serial to run calculations then have the result send back. I am sending two values and only receiving one. I first got it up and running by using serial comms over usb cable and it works perfect. I then made a few alterations to get it sending over bluetooth. The data that is being sent from the Arduino through bluetooth is perfect. When I do calculations and send the result back, however, the values are off. I have a timer Interrupt Service Routine (ISR) running on the Arduino that sends the values at 100Hz. If I slow that down to 10Hz, the response from computer to Arduino gets better and if I slow it down to 1HZ it is perfect. Unfortunately, I really need it to be working well at 100Hz for accurate control of my robot. I have included a link below of a plot of the response at 10Hz. Alpha and Theta are values sent from Arduino, V is a calculation done by python and V_echo is V being sent to Arduino, multiplied by 2 and sent back to python. As you can see, V_echo is broken and jagged when it should be a smooth line like the others. All of this tells me that while the send rate of the HC-05 is fine, the receive rate is too slow. I have changed baud rate possibilities, played with making the HC-05 a master vs. slave and slave-loop... slave works the best. The last thing I can think of is using stop bits. I have pyserial sending two stop bits and have the HC=05 stop bit set to two by using AT+UART=115200,1,0. If stop bits are my solution, I clearly have it set up wrong. I don't know exactly what python does when I include stop bits and furthermore I don't know if I need to do any program that reads the bit or if the HC-05 just understands it... If stop bits are not my answer, I look forward to finding out what is. Thanks again.