Author Topic: another noob trying to debug some code ai threw up on me  (Read 1345 times)

0 Members and 1 Guest are viewing this topic.

Offline drspasticTopic starter

  • Contributor
  • Posts: 26
  • Country: bg
another noob trying to debug some code ai threw up on me
« on: December 30, 2024, 12:03:17 am »
so i played with a little arduino code before and got some examples twisted to do my bidding but im over my head here. im using lolin 32 lite and want it to let me enter a value in a webpage and output a voltage from the dac. ultimately it will generate a 2.4ghz signal going to a mixer but at this stage i just want to test how stable (or not) the output will be.
anyway i thought to try ai and it spewed this:

#include <WiFi.h>
#include <WebServer.h>

// Access Point credentials 
const char* ssid = "vco";
const char* password = ""; // Use a strong password (minimum 8 characters)

// Web server running on port 80 
WebServer server(80);

// HTML for the webpage 
const char webpage[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
  <title>DAC Control</title>
  <style>
    body { font-family: Arial; text-align: center; margin-top: 50px; }
    input { width: 80px; height: 30px; font-size: 16px; }
    button { height: 35px; font-size: 16px; }
  </style>
</head>
<body>
  <h1>ESP32 DAC Control</h1>
  <p>Enter a value (-255) to set the DAC output:</p>
  <form action="/set" method="get">
    <input type="number" name="value" min="" max="255" required>
    <button type="submit">Set DAC</button>
  </form>
</body>
</html>
)rawliteral";

// DAC output pin 
const int dacPin = 25;

void handleRoot() {
  server.send(200, "text/html", webpage);
}

void handleSetValue() {
  if (server.hasArg("value")) {
    int value = server.arg("value").toInt();
    Serial.print("Received value: "); // Debug print 
    Serial.println(value); // Debug print 
    if (value >=  && value <= 255) { // Corrected comparison 
      dacWrite(dacPin, value); // Write the value to the DAC pin 
      server.send(200, "text/plain", "DAC output set to " + String(value));
    } else {
      server.send(400, "text/plain", "Invalid value. Enter a number between  and 255.");
    }
  } else {
    server.send(400, "text/plain", "Value not provided.");
  }
}

void setup() {
  // Initialize serial for debugging 
  Serial.begin(115200);

  // Set up DAC pin 
  pinMode(dacPin, OUTPUT);

  // Initialize WiFi in Access Point mode 
  WiFi.softAP(ssid, password);

  Serial.println("Access Point started.");
  Serial.print("AP IP address: ");
  Serial.println(WiFi.softAPIP());

  // Define web server routes 
  server.on("/", handleRoot);
  server.on("/set", handleSetValue);

  // Start the server 
  server.begin();
  Serial.println("Web server started.");
}

void loop() {
  // Handle incoming client requests 
  server.handleClient();
}



and it returned this:

/home/ide/Desktop/vco2/vco2.ino: In function 'void handleSetValue()':
vco2:46:15: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   46 |     if (value >=  && value <= 255) { // Corrected comparison
      |         ~~~~~~^~~~~~~~~~~~
vco2:46:22: error: label 'value' used but not defined
   46 |     if (value >=  && value <= 255) { // Corrected comparison
      |                      ^~~~~
exit status 1
ISO C++ forbids comparison between pointer and integer [-fpermissive]


this was the best it could do. the webserver part actually works, but no peanut for the rest.
so any ideas what i need to do? or just slate me for trying to let a computer do the work.
im old btw, and used to learn quite well in the days gone by crashing games and playing with the code. if i see the code as it is supposed to be i can usually work out what bits to edit

edit btw i do have the code running by commenting out the offensive idiot check lines, which are not really needed, i just want to know how they SHOULD be formatted if they were to work.
« Last Edit: December 30, 2024, 12:26:28 am by drspastic »
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10407
  • Country: nz
Re: another noob trying to debug some code ai threw up on me
« Reply #1 on: December 30, 2024, 12:06:56 am »
AI should be able to fix that error if you feed it back in along with the error message.
It's a very trivial mistake, the 0 is missing and the brackets should be better.

The line should be
if (value >= 0) && (value <= 255)

I've not gone through the logic, but that is why it wont compile
« Last Edit: December 30, 2024, 12:09:42 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Whales

  • Super Contributor
  • ***
  • Posts: 2133
  • Country: au
    • Halestrom
Re: another noob trying to debug some code ai threw up on me
« Reply #2 on: December 30, 2024, 12:20:36 am »
AI should be able to fix that error if you feed it back in along with the error message.
It's a very trivial mistake, the 0 is missing and the brackets should be better.

The line should be
if (value >= 0) && (value <= 255)

Spoken like a true AI, your suggestion is wrong and won't compile ;)

   if (value >=  && value <= 255)   // Bad
   if (value >= 0) && (value <= 255) // Bad
   if (value >= 0 && value <= 255) // Works

drspastic: You have two comparison operations.  The second one makes sense "value <= 255", but the first one is incomplete "value >=".  Every comparison compares two things.

Psi: "If" statements can't have multiple sets of brackets after them in C or C++.  This would work in python, so perhaps that's where your mind is.
« Last Edit: December 30, 2024, 12:33:05 am by Whales »
 
The following users thanked this post: drspastic

Offline drspasticTopic starter

  • Contributor
  • Posts: 26
  • Country: bg
Re: another noob trying to debug some code ai threw up on me
« Reply #3 on: December 30, 2024, 12:35:22 am »
great, i will throw that up the flagpole tomorrow and see if anyone salutes.
as for the suggestion to ask ai, well of course i tried that 4 or 5 times before asking.
in the end i just commented the lines out to get it working because i know not to enter more than 255 into it!

anyhow its working enough to test signal stability as is. its for a qo100 satellite uplink so i cant have the signal wandering all over the transponder. my backup option is to use mcp4725 dac for 12 bit resolution. if resolution is good enough i might be able to splice in code i adapted a few years ago to do rtty mode and feldhell but thats another story.

btw, thanks guys for not reaming me out for using ai and asking for a fix
« Last Edit: December 30, 2024, 12:37:12 am by drspastic »
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2791
  • Country: us
Re: another noob trying to debug some code ai threw up on me
« Reply #4 on: December 30, 2024, 12:43:33 am »
Psi: "If" statements can't have multiple sets of brackets after them in C or C++.  This would work in python, so perhaps that's where your mind is.

This is not true.  You can have multiple sets of brackets.
What you can't have is multiple conditional statements for the 'if'.

if (value >= 0 && value <= 255) // this is okay

but if you wanted to be more explicit:

if ((value >= 0) && (value <= 255)) // this would make more sense for a more complex condition
 
The following users thanked this post: tooki

Offline drspasticTopic starter

  • Contributor
  • Posts: 26
  • Country: bg
Re: another noob trying to debug some code ai threw up on me
« Reply #5 on: December 30, 2024, 11:36:00 pm »
well i tried both answers and it just threw errors in other places. so i stayed with the version where i deleted that whole sanity check <255 routine.
then i failed the sanity check overall because in the test circuit (which generates 2.4ghz frequencies) as soon as i got the esp32 to output almost the right dac voltage to get the exact output frequency i needed, the output frequency jammed the esp32 wifi and kicked me from the web console. :-DD
so im going to have to think of another plan not involving wifi.

thanks anyway. it was fun
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10407
  • Country: nz
Re: another noob trying to debug some code ai threw up on me
« Reply #6 on: January 01, 2025, 01:27:11 am »
AI should be able to fix that error if you feed it back in along with the error message.
It's a very trivial mistake, the 0 is missing and the brackets should be better.

The line should be
if (value >= 0) && (value <= 255)

Spoken like a true AI, your suggestion is wrong and won't compile ;)

   if (value >=  && value <= 255)   // Bad
   if (value >= 0) && (value <= 255) // Bad
   if (value >= 0 && value <= 255) // Works


ops yeah, in my haste after seeing the missing zero I forgot the final brackets.

   if (value >=  && value <= 255)           // Bad
   if (value >= 0) && (value <= 255)      // Bad
   if (value >= 0 && value <= 255)         // Works but still hard to read
   if ( (value >= 0) && (value <= 255) )  // That's better.  8)
« Last Edit: January 01, 2025, 01:29:25 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf