ESP8266 Wifi Temperature Logger

  • View
    42

  • Download
    1

Embed Size (px)

DESCRIPTION

Introduction to using the esp8266 Wi-Fi module.

Transcript

  • let's make Explore(/tag/typeid/) Publish(/about/create.jsp)

    Featured: IntelIoT(/id/intel/) Kitchen&Bath(/id/Moen/) Parties(/tag/typeid/categorycraft/channelpartiesandweddings/)

    LinkItONE(/id/mediateklinkitone/)

    TheydayIreadathackaday(http://hackaday.com/tag/esp8266/(http://hackaday.com/tag/esp8266/))thatanew$5wifimodulewasavailable,Iorderafewofthemtotest.Now,afewweekslaterIwanttosharemyexperience.

    ThisisaverysimpledemousingtheESP8266andArduinotoupdatearemoteserver(https://thingspeak.com/)usingadigitaltemperaturesensor.

    ThesearereallyexcitingtimesfortheInternetofThings(r)evolution.PricesarecomingdownandtheMakercommunityiseagertodevelopthenextgenerationofallthingsconnected.

    Thefollowingsetupcouldbedoneunder$20.Thisisusingofftheshelf"pricey"components(likeArduino),butyoucouldprogramyourownMCUwithUARTsupportandmakeitcheaper.

    Step1:Materials

    (/file/F0FZH4CI0RYTMAP/)

    AboutThisInstructable

    451,822views

    v

    361favorites

    License:

    (/member/noelportugal/)

    noelportugal(/member/noelportugal/)Myblog(http://noelportugal.blogspot.com/)

    Follow 80

    Morebynoelportugal:

    (/id/Halloween

    PumpkinPayNFCEnabledPumpkins/)

    (/id/ESP8266Wifi

    TemperatureLogger/)

    (/id/Interactive

    MagicMirrorwithCandyDispenser/)

    ESP8266(/tag/typeid/keywordESP8266/)

    arduino(/tag/typeid/keywordarduino/)

    internetofthings(/tag/typeid/keywordinternet%20of%20things/)

    temperature(/tag/typeid/keywordtemperature/)

    iot(/tag/typeid/keywordiot/)

    thingspeak(/tag/typeid/keywordthingspeak/)

    cheapwifi(/tag/typeid/keywordcheap%20wifi/)

    Tags:

    Related

    (/id/ESP8266

    wirelessloggerESP8266NodeMCUv1.0withArduinoIDE(/id/ESP8266NodeMCUv10ESP12EwithArduinoIDE/)WIFIplantmonitoringsystembasedonArduinoMEGAandESP8266(/id/WIFIplantmonitoring

    (/)share what you make >

    Login(/account/login) | SignUp(/account/gopro?sourcea=header)

  • 1xESP8266(http://www.electrodragon.com/product/esp8266wi07cwifimodule/(http://www.electrodragon.com/product/esp8266wi07cwifimodule/))1xArduinoProMini3283.3V/8MHz(https://www.sparkfun.com/products/11114(https://www.sparkfun.com/products/11114))1xDS18B20DigitalTemperatureSensor(http://www.mouser.com/ProductDetail/MaximIntegrat...(http://www.mouser.com/ProductDetail/MaximIntegrated/DS18B20+/?qs=sGAEpiMZZMvbyeSUH4qH%2fLbikZ7SIep9)1x4.7kresistor1xPowersupply(3.3Vupto12V,Iuseda9v)

    Step2:ESP8266Setup

    (/file/F9RJB5KI0RYRV30/)

    (/file/FS9I33ZI0RYS6HN/)

    (/id/WIFI(/id/WIFIplantmonitoringsystembasedonArduino

    (/id/Makers

    DIYPCBbreakoutforESP8266(ESP01)Maker'sIoTKit(/id/MakersIoTKitforESP8266ESP01/)byshinteo(/member/shinteo/)

    (/id/An

    AninexpensiveIoTenablerusingESP8266(/id/AninexpensiveIoTenablerusingESP8266/)bygopinath.marappan

    (/id/ESP8266

    ESP8266WiFirelayswitch(/id/ESP8266WiFirelayswitch/)byEasyIoT(/member/EasyIoT/)

  • Thisiswherethingsgottricky.Ispentalotoftimetestingdifferentconfigurations.NotethataretwoversionoftheESP8266goingaround.ThefirstonehasthenotificationLEDsrightnexttotheboardpins.Thesecondone(newer)hastheLEDsbytheantenna.Ihavethesecondone.

    ThebestresultscamewhenIloadedV0.922whichallowedmetochangethebaudrateto9600.Followthesestepstoloadthisfirmware.

    http://www.electrodragon.com/w/Wi07c#Firmware_uploading_tool(http://www.electrodragon.com/w/Wi07c#Firmware_uploading_tool)

    ThebestwaytotestagoodconnectionisbyusingaUSBtoTTLcableandusingaterminallikeCoolTerm.Hereisthecommandtochangethebaudrate:

    AT+CIOBAUD=9600

    ThesearethepinconnectionsIusedonESP8266toUSBtoTTL.Iusedtheregulated3.3vvccoftheArduinotopowertheESP8266.IknowthatArduinovcc3.3vmaxisoutputis150mAandESP8266willpeakat240mA.ButatthetimeIhadnootherregulated3.3vavailable.RegularusagefortheESP8266isat70mA.

    RemembertoconnectGPIO0toGNDwhenyouareuploadingnewfirmware.Afterthatremovefornormaloperation.

    UTXD>RX(USBtoTTL)

    CH_PDVCC

    RST

    VCC>VCC(powersource)

    GND>GND(powersource)

    GPIO2

    GPIO0

    URXD>TX(USBtoTTL)

    *NotealsohadtodoUSBtoTTLGNDtoArduinoGND

    (/file/FSQTKOYI0RYRV1U/)

  • Step3:ArduinoSetupandSketch

    ESP8266toArduino

    UTXD>RXArduino

    CH_PDVCC

    RST

    VCC>VCCArduino

    GND>GNDArduino

    GPIO2

    GPIO0

    URXD>TXArduino

    DigitalTemperatureSensortoArduino

    ArduinoGND>DS18B20GND(1)>DS18B20VDD(3)

    DS18B20DQ(2)>4.7KR>VCCArduino3.3v

    #include#include#include#include#defineONE_WIRE_BUS8OneWireoneWire(ONE_WIRE_BUS);DallasTemperaturesensors(&oneWire);#defineSSID"[YOUR_SSID]"#definePASS"[YOUR_PASSWORD]"#defineIP"184.106.153.149"//thingspeak.comStringGET="GET/update?key=[THINGSPEAK_KEY]&field1=";SoftwareSerialmonitor(10,11);//RX,TX

    (/file/FBF8ATCI0RYS6HJ/)

  • SoftwareSerialmonitor(10,11);//RX,TX

    voidsetup(){monitor.begin(9600);Serial.begin(9600);sensors.begin();sendDebug("AT");delay(5000);if(Serial.find("OK")){monitor.println("RECEIVED:OK");connectWiFi();}}

    voidloop(){sensors.requestTemperatures();floattempC=sensors.getTempCByIndex(0);tempC=DallasTemperature::toFahrenheit(tempC);charbuffer[10];StringtempF=dtostrf(tempC,4,1,buffer);updateTemp(tempF);delay(60000);}

    voidupdateTemp(StringtenmpF){Stringcmd="AT+CIPSTART=\"TCP\",\"";cmd+=IP;cmd+="\",80";sendDebug(cmd);delay(2000);if(Serial.find("Error")){monitor.print("RECEIVED:Error");return;}cmd=GET;cmd+=tenmpF;cmd+="\r\n";Serial.print("AT+CIPSEND=");Serial.println(cmd.length());if(Serial.find(">")){monitor.print(">");monitor.print(cmd);Serial.print(cmd);}else{sendDebug("AT+CIPCLOSE");}if(Serial.find("OK")){monitor.println("RECEIVED:OK");}else{monitor.println("RECEIVED:Error");}}voidsendDebug(Stringcmd){monitor.print("SEND:");monitor.println(cmd);Serial.println(cmd);}booleanconnectWiFi(){Serial.println("AT+CWMODE=1");delay(2000);Stringcmd="AT+CWJAP=\"";cmd+=SSID;cmd+="\",\"";cmd+=PASS;cmd+="\"";sendDebug(cmd);delay(5000);if(Serial.find("OK")){monitor.println("RECEIVED:OK");returntrue;}else{monitor.println("RECEIVED:Error");returnfalse;

  • returnfalse;}}

    *UPDATE.Onceyourdonetesting/monitoring.LoadthesamesketchwithoutSoftwareSerialMonitor.Thisgavemebetterresultsasstandalone.

    #include#include#include#defineONE_WIRE_BUS8OneWireoneWire(ONE_WIRE_BUS);DallasTemperaturesensors(&oneWire);

    #defineSSID"[YOUR_SSID]"#definePASS"[YOUR_PASSWORD]"#defineIP"184.106.153.149"//thingspeak.comStringGET="GET/update?key=[THINGSPEAK_KEY]&field1=";

    voidsetup(){Serial.begin(9600);sensors.begin();Serial.println("AT");delay(5000);if(Serial.find("OK")){connectWiFi();}}

    voidloop(){sensors.requestTemperatures();floattempC=sensors.getTempCByIndex(0);tempC=DallasTemperature::toFahrenheit(tempC);charbuffer[10];StringtempF=dtostrf(tempC,4,1,buffer);updateTemp(tempF);delay(60000);}

    voidupdateTemp(StringtenmpF){Stringcmd="AT+CIPSTART=\"TCP\",\"";cmd+=IP;cmd+="\",80";Serial.println(cmd);delay(2000);if(Serial.find("Error")){return;}cmd=GET;cmd+=tenmpF;cmd+="\r\n";Serial.print("AT+CIPSEND=");Serial.println(cmd.length());if(Serial.find(">")){Serial.print(cmd);}else{Serial.println("AT+CIPCLOSE");}}

    booleanconnectWiFi(){Serial.println("AT+CWMODE=1");delay(2000);Stringcmd="AT+CWJAP=\"";cmd+=SSID;cmd+="\",\"";cmd+=PASS;cmd+="\"";Serial.println(cmd);delay(5000);if(Serial.find("OK")){returntrue;

  • returntrue;}else{returnfalse;}}

    Step4:ThingSpeaksetup

    ThinkSpeakisjustawesome!Followthesesimplestepstostartyouownfeed:

    1. SignupforaFREEaccountathttps://thingspeak.com/(https://thingspeak.com/)

    2. GotoChannels>CreateNewChannel(youcanleavealldefaults)3. GotoAPIKeysandgetyourKEY4. Testbyputtingthisonyourbrowser

    http://api.thingspeak.com/update?key=[THINGSPEAK_KEY]&field1=05. Checkyourresults

    http://api.thingspeak.com/channels/[CHANNEL_ID]/feed.json?key=[THINGSPEAK_KEY]

    Nowyouarereadytostartsendingdata.

    (/file/FYX511HI0RYS6A4/)

    Getting Started with ThingSpeak - ThingSpeak Introduction

    0:03 / 2:04

  • Wehaveabenicecommentpolicy.Pleasebepositiveandconstructive. XIMadeit! b AddImages PostComment

    Reply8monthsagogphat(/member/gphat)whenIrunthissketch,ishowasbelow

    ATAT+CIPSTART="TCP","184.106.153.149",80AT+CIPSEND=54AT+CIPCLOSEAT+CIPSTART="TCP","184.106.153.149",80AT+CIPSEND=54AT+CIPCLOSEAT+CIPSTART="TCP","184.106.153.149",80AT+CIPSEND=54AT+CIPCLOSEAT+CIPSTART="TCP","184.106.153.149",80AT+CIPSEND=54AT+CIPCLOSEAT+CIPSTART="TCP","184.106.153.149",80AT+CIPSEND=54AT+CIPCLOSEAT+CIPSTART="TCP","184.106.153.149",80AT+CIPSEND=54Icantuploadtothingspeak.the2ledonespstillon,IconnectnothingtoUno.hereismycode

    #include

    #defineSSID""//Ideleteitwhenposthere#definePASS""//Ideleteitwhenposthere

    #defineIP"184.106.153.149"//thingspeak.comStringGET="GET/update?key=EDPAJHIWQLX2A8VB&field1="SoftwareSerialmonitor(10,11)//RX,TX

    voidsetup(){monitor.begin(9600)Serial.begin(9600)

    sendDebug("AT")delay(1000)if(Serial.find("OK")){monitor.println("RECEIVED:OK")connectWiFi()}}

    voidloop(){

    StringtempF=String(5.4,DEC)updateTemp(tempF)delay(1000)}

    voidupdateTemp(StringtenmpF){Stringcmd="AT+CIPSTART=\"TCP\",\""cmd+=IPcmd+="\",80"sendDebug(cmd)delay(1000)if(Serial.find("Error")){monitor.print("RECEIVED:Error")return}cmd=GETcmd+=tenmpFcmd+="\r\n"Serial.print("AT+CIPSEND=")

  • Reply

    16daysago

    Reply2monthsago

    Reply7monthsago

    Serial.println(cmd.length())if(Serial.find(">")){monitor.print(">")monitor.print(cmd)Serial.print(cmd)}else{sendDebug("AT+CIPCLOSE")}if(Serial.find("OK")){monitor.println("RECEIVED:OK")}else{monitor.println("RECEIVED:Error")}}voidsendDebug(Stringcmd){monitor.print("SEND:")monitor.println(cmd)Serial.println(cmd)}

    booleanconnectWiFi(){Serial.println("AT+CWM

Recommended

View more >