A place to put your YouTube video that is ESP8266 related.

User avatar
By danbicks
#28967 Hi Freedom,

The posts are still waiting approval, move's slow on B4a forum lol.

Just out of curiosity what version of b4a are you running? I still have 2.50 may need to speak with Erel and update to later version. The circuit is cool, nice addition of mosfet to switch the heater on in the MQ-3, normally these take quite some time to stabilize before readings are accurate. How are you controlling this? turn on fet, take an average over ten samples, fet off publish to android results?

Great work, really looking forward to having a tinker with it.

Dans

PS: Any chance of posting the Ino code here so I can look at your magic code:) Cheers buddy
User avatar
By freedom2000
#28971 Part of the Magic code is here (simple really simple !)

Code: Select allvoid loop()
{
  // put your main code here, to run repeatedly:
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    Timeout = millis();          //rearm software watchdog
    digitalWrite(Sensor, HIGH);  //switch on heater (and off after 5 seconds without dialog)

    // read the packet into packetBufffer
    int len = Udp.read(packetBuffer, 255);
    if (len > 0) {
      packetBuffer[len] = 0;
    }
    String Res;
    String test;
   
    test = packetBuffer;
    if (test == "Get")// send a reply, to the IP address and port that sent us the packet we received
    {
      GetAlcohol();
      Res = AlcoholRaw;
      Res = "$$$"+ Res;
      if (AlcoholRaw > 1023) AlcoholRaw = 0;
      SendUDP(Res);
    }
    else if (test == "ID")// send a reply, to the IP address and port that sent us the packet we received
    {
      Res = "eBreathalyzer";
      SendUDP(Res);
    }
    else if (test.startsWith("SSID :"))// send a reply, to the IP address and port that sent us the packet we received
    {
      esid = test.substring(6);
      SendUDP("okSSID");
    }
    else if  (test.startsWith("PASS :"))// send a reply, to the IP address and port that sent us the packet we received
    {
      epass = test.substring(6);
      SendUDP("okPASS");
      eepromUpdate();
      delay(1000);
      abort();
    }
  }
}


and for the sensor it is not more complicated !
just averaging the values

Code: Select allvoid GetAlcohol()
{
      int i;
      for (i = 0; i<10; i++)
      {
        delay(50);               //wait 50ms to allow good ADC conversion
        AlcoholRaw  += analogRead(A0);
      }
      AlcoholRaw = AlcoholRaw/10; //average /10
}
User avatar
By danbicks
#28975 freedom,

Awesome, love the code. Did you have to configure the A>D in setup in any special way?

Code looks really cool, I can see that the Android app requests data from the ESP governed by a timer in the Android app.
Great project JP. I have UDP working in my garden controller, now I need to work on the android APP to control it. My plan is to have 5 seek bars for setting different PWM levels of the lights and saving the values as different mood settings.
Hardware is all done, just in the process of boxing it up and getting it ready for prime time. Shame summer in England is so poor it will probably be next year I get to enjoy it, you never know we might have an Indian summer in England :)

Best regards

Dans
User avatar
By freedom2000
#28989 HI

Nothing to do to have the ADC work, just the hardware as described.

Yes Android App is governed by a Timer @5Hz and requests sample to ESP

To send UDP (from ESP8266) the code is

Code: Select allvoid SendUDP(String Res)
{
      char  ReplyBuffer[] = "";       // a string to send back
      Res.toCharArray(ReplyBuffer, Res.length()+1);
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Udp.write(ReplyBuffer);
      Udp.endPacket();
}