So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By liderbug
#70056 Thought I'd share


HW: RasPi-3, Raspbarian, ESP8266 (w uUSB, Rst,Flash buttons). A breakout board to connect the TMP36. SW: Ardunio IDE (arm).
Code: Select alllsomod | grep usb
     usbserial              29943  1 cp210x

Problems: Here's the 8622, documentation - HA! Ard-IDE, documentation by people who wrote the code or have been using it for a loooong time. So let me make some observation: I run ArdIDE via VNC. After download and install click on Programming->ArdIDE and up pops the last (or new) blank file. Aside: I use VI - this editor is not vim - once use to how things work you can write a bit, "Save" and edit with your fav editor and File->Open Recent. You're going to write C code.

First thing: Tools->Board [NodeMCU esp-12e], 80Mhz, 4M, 115200, /dev/ttyUSB0.
A new Sketch (program) shows "void setup() and void loop(). Depending on your program "#include <whatever.h> goes above setup [ init by any other name] and the rest of your code in loop [main by any other name]

Top right of the edit window is a MagGlass w "+" - that brings up "Serial Monitor" [a console window] and you can output debug statements - make sure it's set to 9600 baud. So in setup() Serial.begin(9600); then in loop() Serial.print("your text"); ...println adds a CR, ... printf works just fine [except: float %4.1f (any %f) doesn't work on a RasPi. Ardunio yes, Pi no]

Google is your best friend. There's lots of sample code out there - none of it exactly what you want to do - but it will send you in the right direction.

This works for me
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

IPAddress ip(192, 168, 0, 32);
IPAddress gateway(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress DNS(8, 8, 8, 8);
const char* ssid     = "CaseSenSSID";
const char* password = "yourVerySecPassword";
ESP8266WebServer server(80);  // web port ?8080?8088?
double degF;

void setup()
{
    //Serial.begin(9600);
    WiFi.config(ip, gateway, subnet, DNS);
    delay(100);
    WiFi.begin(ssid, password);
    //Serial.print("Connecting");   // all Serial console printing commented out
    while (WiFi.status() != WL_CONNECTED) {
        //Serial.print(".");
        delay(200);
    }
    while (WiFi.waitForConnectResult() != WL_CONNECTED) {
      //Serial.println();
      //Serial.println("Fail connecting");
      delay(5000);  // wait 5 seconds
      ESP.restart();
    }
    //Serial.print("   OK  ");
    //Serial.print("Module IP: ");
    //Serial.println(WiFi.localIP());
    server.on("/", handleTempPath); 
    server.begin();
    //Serial.println("Server listening");
}

// everybody else gets the voltage from A0, then calcs the degC then calcs the degF or I justrunitalltogether.

void loop() {
   degF = (((( analogRead(A0) / 1024.0) * 3.2) - 0.5) * 100.0) * 1.8 + 32;
        server.handleClient();  // did we get a http request
   delay (2500);  //  stops free run ... and I'm only going to read every 5 minutes.
                              // causes a slight delay returning temp.
}

void handleTempPath ()  // "Temp"erature
{
        // as above on a RasPi printf (... %4.1f", degF)  returns %.1f
        // I mean percent period one f - there's an open ticket
        // so Double to Srt Func works - below equiv to  %5.1f and for some reason
        // needs a scratch pad to work from :-/
   char test[16];
   char buffer[16];
   sprintf (buffer, "%s\n", dtostrf(degF ,5, 1, test));
   //Serial.println (buffer);
   server.send(200, "text/plain", buffer);
}