DEVLOG #8
##What I did
These 7 hours, I basically spent trying to get the HTTP POST request to work. I had a lot of trouble when trying to get it to work, but I was able to find a way to get the prompt to the AI and the response back to the ESP.
##Challenges
####Getting the POST to work
Initially, I had decided to scrap the MCP idea and to just send an HTTP request directly to Ollama. This plan should have worked, but I could not get it to function. For some reason, I kept receiving a response code of -1 when I tried to send the request. This code means the connection was refused, and this could happen for a multitude of reasons. After some simple troubleshooting, I deduced that the problem was likely related to my firewall. You see, Ollama runs on port 11434, which is protected by the firewall. It also only listens to 127.0.0.1, which meant that I could not send data from the ESP32. To fix the IP problem, I tried setting an environment variable to allow it to listen on 0.0.0.0, but this didn’t work. Then I tried exposing port 11434 on my firewall to the IP of my ESP32, but that was also unsuccessful. I even tried connecting the ESP and my computer to my phone’s hotspot, but that also yielded -1. After consulting Google’s Gemini for any other solutions, I decided that I should just create a Python file that would handle all the requests. So I created a file, installed FastAPI with Uvicorn, and used those libraries along with requests to send an API request to Ollama’s REST API, which I could then return to the ESP. The ESP sent the prompt to the Python script via HTTPClient and ArduinoJSON. After creating all of this, I was finally able to get a response from the AI in serialized JSON, and I am currently trying to figure out why I can’t deserialize it and print it.
##What is next
As I mentioned above, I will continue trying to find a way to print only the response and to send prompts seamlessly. This part of the project was definitely very frustrating, but I am so happy I was able to make it possible. Thanks.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.