Skip to content

Commit

Permalink
add hostname function
Browse files Browse the repository at this point in the history
change hostname to led-tree
  • Loading branch information
jcksnvllxr80 committed Jan 3, 2022
1 parent 51a9e42 commit 48bdba1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion conf/example_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"wifi": {
"ssid": "VGhpcyBpcyBub3QgYSByZWFsIFNTSUQ=",
"password": "VGhpcyBpcyBhIG5vdCBhIHJlYWwgUDQkJHcwcmQh"
"password": "VGhpcyBpcyBhIG5vdCBhIHJlYWwgUDQkJHcwcmQh",
"hostname": "pico-led-tree"
},
"time_api": {
"host": "worldtimeapi.org",
Expand Down
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
COLON = ':'
OPENING_BRACE = '{'
CLOSING_BRACE = '}'
WIFI_MODE = 3
WIFI_CHECK_PERIOD = 3_600_000 # milliseconds (hourly)
# HOURS_PER_DAY = 24
# HOURS_TO_SYNC_TIME = list(range(HOURS_PER_DAY))
Expand Down Expand Up @@ -145,7 +146,9 @@ def init_esp8266():
'''
set the current WiFi in SoftAP+STA
'''
esp01.setCurrentWiFiMode()
esp01.setCurrentWiFiMode(WIFI_MODE)
esp01.deviceHostname(config["wifi"]["hostname"])
print(esp01.deviceHostname())
# apList = esp01.getAvailableAPs()
# for items in apList:
# print(items)
Expand Down
25 changes: 25 additions & 0 deletions wifi/esp8266.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,31 @@ def disconnectWiFi(self):
else:
return False

def deviceHostname(self,hostname=None):
"""
This function is used to set a hostname for ESP8266
Return:
False on failed to set hostname
True on successfully set hostname
"""
if hostname:
retData = self._sendToESP8266("AT+CWHOSTNAME=\"{}\"\r\n".format(hostname))
if(retData != None):
print(str(retData))
if ESP8266_OK_STATUS in retData:
return True
else:
return False
else:
return False
else:
retData = self._sendToESP8266("AT+CWHOSTNAME?\r\n")
if(retData != None):
return str(retData)
else:
return False

def _createTCPConnection(self, link, port=80):
"""
This function is used to create connect between ESP8266 and Host.
Expand Down

0 comments on commit 48bdba1

Please sign in to comment.