homecontrol-neopixel: minor updates
This commit is contained in:
		
							parent
							
								
									1367690f70
								
							
						
					
					
						commit
						f5288ef30e
					
				
					 1 changed files with 9 additions and 8 deletions
				
			
		
							
								
								
									
										17
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								main.py
									
										
									
									
									
								
							|  | @ -8,8 +8,9 @@ import math | ||||||
| import wifi | import wifi | ||||||
| 
 | 
 | ||||||
| CONFIG = "config.json" | CONFIG = "config.json" | ||||||
| ADDRESS = "http://192.168.11.21:5000" | NUM_PIXEL = 24 | ||||||
| TIMEOUT_UPDATE = 1 | ADDRESS = "http://192.168.11.11:5000" | ||||||
|  | TIMEOUT_UPDATE = 5 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ActorNP: | class ActorNP: | ||||||
|  | @ -28,24 +29,24 @@ class ActorNP: | ||||||
|         if not self.config.get("type"): |         if not self.config.get("type"): | ||||||
|             update_config = True |             update_config = True | ||||||
|             self.config["type"] = "neopixel" |             self.config["type"] = "neopixel" | ||||||
|         if not self.config.get("levels"): |         if not self.config.get("maxLevel"): | ||||||
|             update_config = True |             update_config = True | ||||||
|             self.config["levels"] = 0xffffff |             self.config["maxLevel"] = 0xffffff | ||||||
|         if update_config: |         if update_config: | ||||||
|             with open(CONFIG, "w") as config_file: |             with open(CONFIG, "w") as config_file: | ||||||
|                 ujson.dump(self.config, config_file) |                 ujson.dump(self.config, config_file) | ||||||
| 
 | 
 | ||||||
|         self.id_a = self.config["id"] |         self.id_a = self.config["id"] | ||||||
|         self.type_a = self.config["type"] |         self.type_a = self.config["type"] | ||||||
|         self.levels = self.config["levels"] |         self.maxLevel = self.config["maxLevel"] | ||||||
|         self.color = (0, 0, 0) |         self.color = (0, 0, 0) | ||||||
|         self.np = neopixel.NeoPixel(machine.Pin(2), 16) |         self.np = neopixel.NeoPixel(machine.Pin(2), NUM_PIXEL) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     def update(self): |     def update(self): | ||||||
|         url = "%s/actors/update" % ADDRESS |         url = "%s/actor/update" % ADDRESS | ||||||
|         level = ((self.color[0] << 16) + (self.color[1] << 8) + self.color[2]) & 0xffffff |         level = ((self.color[0] << 16) + (self.color[1] << 8) + self.color[2]) & 0xffffff | ||||||
|         data = {"id": self.id_a, "type": self.type_a, "levels": self.levels, "level": level} |         data = {"id": self.id_a, "type": self.type_a, "maxLevel": self.maxLevel, "level": level} | ||||||
|         try: |         try: | ||||||
|             res = requests.post(url, json=data) |             res = requests.post(url, json=data) | ||||||
|             content = res.json() |             content = res.json() | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue