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

User avatar
By hackerjoe
#84801 Hi Shufti,

This is the temp code I have working on my LAN using a browser.
I'm looking to just get Fahrenheit to up write to ThingSpeak.
If possible I'd like to still have it write to a browser on my network.
Thank you,
Joe
I used Ralph Bacons code from YouTube to get the random data sent to ThingSpeak but for the life of me I don't know how to splice this code into his to get the correct Fahrenheit data sent at least every hour.
Any help is appreciated.
Here is what I have and hopefully it's not too much garbage remember I'm a noobie -->

#include <ESP8266WiFi.h>
#include <math.h>
// http://arduino.esp8266.com/stable/packa ... index.json
unsigned int Rs = 150000;
double Vcc = 3.3;
// WiFi parameters
const char* ssid = "**********";
const char* password = "********************";
// Pin
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
// Init DHT
// Connect to WiFi network
WiFi.mode(WIFI_STA);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
delay(1000);
float temp = Thermister(AnalogRead());
float temperatureF = (temp * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");
//Serial.print(Thermister(AnalogRead())); Serial.println(" degrees C");
WiFiClient client = server.available();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE html>");
client.println("<html xmlns='http://www.w3.org/1999/xhtml'>");
client.println("<head>\n<meta charset='UTF-8'>");
client.println("<title>F-HIVE Wifi Temp Sensor</title>");
client.println("<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet'>");
client.println("</head>\n<body>");
client.println("<div class='container'>");
client.println("<div class='panel panel-default' margin:15px>");
client.println("<div class='panel-heading'>");
client.println("<H2>******** Wifi Temp Sensor</H2>");
client.println("<div class='panel-body' style='background-color: powderblue'>");
client.println("<pre>");
client.print("Temperature (°F) : ");
client.print(temperatureF);
client.print('\n');
//client.print("Temperature (°C) : ");
//client.println(temp, 2);
client.println("</pre>");
client.println("</div>");
client.println("</div>");
client.println("</div>");
client.print("</body>\n</html>");
}
int AnalogRead() {
int val = 0;
for(int i = 0; i < 20; i++) {
val += analogRead(A0);
delay(1);
}
val = val / 20;
return val;
}
double Thermister(int val) {
double V_NTC = (double)val / 1024;
double R_NTC = (Rs * V_NTC) / (Vcc - V_NTC);
R_NTC = log(R_NTC);
double Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * R_NTC * R_NTC ))* R_NTC );
//Temp = Temp - 273.15;
Temp = Temp - 303.01;
return Temp;
}
User avatar
By schufti
#84805 sorry, but your "server" code doesn't make sense to me.
I am no expert on http-server on esp8266.
All I see is code that loops every second sending a html page to ??? probably a client that connected to the esp.
Maybe we can build something from the HelloServer example from ESP8266WebServer library?
User avatar
By hackerjoe
#84806
schufti wrote:sorry, but your "server" code doesn't make sense to me.
I am no expert on http-server on esp8266.
All I see is code that loops every second sending a html page to ??? probably a client that connected to the esp.
Maybe we can build something from the HelloServer example from ESP8266WebServer library?

No worries the server code just creates a webpage that I can view on my LAN.
I'm looking to just take the sensor code & wifi code from it and splice it in to something that will write to tsp.
That code works on my local LAN using the 10k thermistor w/ a 150k resistor on it.