wifi

Arduino specifieke Software
Berichten: 16
Geregistreerd: 21 Feb 2021, 18:46

wifi

Berichtdoor Armira » 06 Mrt 2022, 17:53

Heb nu het volgende probleem:
heb een arduino mega 2560 met ingebouwde wifi
https://www.vanallesenmeer.nl/Uno-WiFi-R3-ATmega2560-ESp8266-8Mb-USB-TTL-CH340G-Development-Board?gclid=EAIaIQobChMIrJWVg-ix9gIV3Y9oCR2euQnLEAQYASABEgKnqfD_BwE

heb de volgende code op de esp gedownload
Code: Alles selecteren
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

const char* host = "WiFi_Fairmount_NodeMCU";
const char* ssid = "WiFi_Fairmount";

ESP8266WebServer server(80);

void setup() {
  Serial.begin(9600);
 

// Connecting WiFi

  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid);
// Starting WEB-server
   
     server.on ( "/", HTTP_handleRoot );
     server.onNotFound ( HTTP_handleRoot );
     server.begin();   
     
}

void loop() {
  server.handleClient();
   delay(50);
}

void HTTP_handleRoot(void) {

if( server.hasArg("State") ){
       Serial.println(server.arg("State"));
  }
 
  server.send ( 200, "text/html", "" );
  Serial.println("send");
}

en op de mega zelf deze code:
Code: Alles selecteren
#include "WiFiEsp.h"

#define HC06 Serial2
unsigned long dur;
const int SERIAL_BUFFER_SIZE = 8;
char serialBuffer[SERIAL_BUFFER_SIZE];

boolean newData = false;
const byte numChars = 32;
char receivedChars[numChars];   // an array to store the received data
int   Blt = atol(receivedChars);

void setup() {
   
Serial.begin(9600);
Serial3.begin(115200);
HC06.begin(9600);
 
  }

  void loop() {


//------------WIFI-----------------------------I

   static byte ndx = 0;
   long now = millis();
        char rc;
        char endMarker = '>';
  static long lastReceived= millis();

while (Serial3.available() && newData == false) {
     rc = Serial3.read();
     
        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) { ndx = numChars - 1; }   
        } else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
               lastReceived = now;
       Blt = atol(receivedChars); }
   Serial3.print("wifi");   
Serial.println(Blt);
Serial.println(receivedChars);
}
   
//------------BLUETOOTH-----------------------------I
 while( (HC06.available()>0) &&( newData == false)) {
        rc = HC06.read();
       
        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {  ndx = numChars - 1; } 
        } else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
               lastReceived = now;
       Blt = atol(receivedChars);   
    }
 Serial.print(" Blt= ");
 Serial.println(Blt);
         
  }
 // if (now-lastReceived >2000){ failsave();}



newData = false;



  }


Deze code heeft goed gewerkt als ik vanaf mijn telefoon dmv een app een cijfer verstuurde
nu echter zie ik dat er wel iets binnen komt maar krijg in Blt alleen maar 0 als resultaatals ik via de wifi iets verstuur via bluetooth werkt het wel
Mijn hele code ziet er als volgt uit:
Code: Alles selecteren
https://www.dropbox.com/s/kx9rvlr9tk1rtwi/Fairmont_alpine2.ino?dl=0

hiermee bestuur ik een modelboot alles werkt de RC en de Bluetooth alleen de wifi wil niet meer
de app die ik gemaakt heb zend de zelfde cijfers met eind marker (>) via bluetooth als met de wifi naar de arduino
de Bluetooth werkt wel goed
wie weet wat ik fout doe??

Advertisement

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 22 gasten