Jump to content
ELFORUM - Forumul electronistilor

esp8266 unsigned int ce valoare maxima are ?


digix

Recommended Posts

Intr-un proiect recent finalizat am folosit unsigned int si ma asteptam sa faca "roll over" la 65.535 dar a mers mai departe.

 

Sa fie esp8266 compatibil cu Due si sa stocheze unsigned int pe 4 byte adica valori pana la 4.294.967.295 ?

Link to comment

Procesorul din ESP este pe 32 de biti asa ca e foarte probabil ca unsigned int sa fie de 4 byte.

Compatibil cu Due in ce sens? Si acolo ai tot un procesor pe 32 biti.

Link to comment

Tipurile de date "standard", (char, (unsigned) int...) sunt neportabile, putand exista diferente intre arhitecturi (cum e cazul aici). De aceea se recomanda folosirea variantelor "portabilzate": (u)int8_t pentru (unsigned) char (intregi pe 8 biti), (u)int16_t pentru intregi pe 16 biti...

Edited by Liviu M
Link to comment

Tipurile de date "standard", (char, (unsigned) int...) sunt neportabile, putand exista diferente intre arhitecturi (cum e cazul aici). De aceea se recomanda folosirea variantelor "portabilzate": (u)int8_t pentru (unsigned) char (intregi pe 8 biti), (u)int16_t pentru intregi pe 16 biti...

 

Dar pentru aceasta trebuie sa existe o "librarie ( :) ) stdint.h facuta special pentru acel procesor / uC si trebuie inclusa in proiect.

Edited by mars01
Link to comment

Este (exista, adica).


Si nu, nu trebuie inclusa special in proiect, e inclusa "default". Cel putin cand lucrezi in "mediul" *) Arduino.

 

*) Habar n-am care ar fi termenul cel mai potrivit aici.

Edited by Liviu M
Link to comment
  • 9 months later...

Buna ziua, de curand am cumparat o placa ESP8266 NODEMCU V3 si neavand eperienta am inceput sa ma joc cu ea, si sa instalez diferite coduri. Dupa instalarea urmatorului cod 

#include <ESP8266WiFi.h>

//////////////////////
// WiFi Definitions //
//////////////////////
const char WiFiAPPSK[] = "sparkfun";

/////////////////////
// Pin Definitions //
/////////////////////
const int LED_PIN = 5; // Thing's onboard, green LED
const int ANALOG_PIN = A0; // The only analog pin on the Thing
const int DIGITAL_PIN = 12; // Digital pin to be read

WiFiServer server(80);

void setup() 
{
  initHardware();
  setupWiFi();
  server.begin();
}

void loop() 
{
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Read the first line of the request
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();

  // Match the request
  int val = -1; // We'll use 'val' to keep track of both the
                // request type (read/set) and value if set.
  if (req.indexOf("/led/0") != -1)
    val = 0; // Will write LED low
  else if (req.indexOf("/led/1") != -1)
    val = 1; // Will write LED high
  else if (req.indexOf("/read") != -1)
    val = -2; // Will print pin reads
  // Otherwise request will be invalid. We'll say as much in HTML

  // Set GPIO5 according to the request
  if (val >= 0)
    digitalWrite(LED_PIN, val);

  client.flush();

  // Prepare the response. Start with the common header:
  String s = "HTTP/1.1 200 OK\r\n";
  s += "Content-Type: text/html\r\n\r\n";
  s += "<!DOCTYPE HTML>\r\n<html>\r\n";
  // If we're setting the LED, print out a message saying we did
  if (val >= 0)
  {
    s += "LED is now ";
    s += (val)?"on":"off";
  }
  else if (val == -2)
  { // If we're reading pins, print out those values:
    s += "Analog Pin = ";
    s += String(analogRead(ANALOG_PIN));
    s += "<br>"; // Go to the next line.
    s += "Digital Pin 12 = ";
    s += String(digitalRead(DIGITAL_PIN));
  }
  else
  {
    s += "Invalid Request.<br> Try /led/1, /led/0, or /read.";
  }
  s += "</html>\n";

  // Send the response to the client
  client.print(s);
  delay(1);
  Serial.println("Client disonnected");

  // The client will actually be disconnected 
  // when the function returns and 'client' object is detroyed
}

void setupWiFi()
{
  WiFi.mode(WIFI_AP);

  // Do a little work to get a unique-ish name. Append the
  // last two bytes of the MAC (HEX'd) to "Thing-":
  uint8_t mac[WL_MAC_ADDR_LENGTH];
  WiFi.softAPmacAddress(mac);
  String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
                 String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
  macID.toUpperCase();
  String AP_NameString = "ESP8266 Thing " + macID;

  char AP_NameChar[AP_NameString.length() + 1];
  memset(AP_NameChar, 0, AP_NameString.length() + 1);

  for (int i=0; i<AP_NameString.length(); i++)
    AP_NameChar[i] = AP_NameString.charAt(i);

  WiFi.softAP(AP_NameChar, WiFiAPPSK);
}

void initHardware()
{
  Serial.begin(115200);
  pinMode(DIGITAL_PIN, INPUT_PULLUP);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
  // Don't need to set ANALOG_PIN as input, 
  // that's all it can be.
}

placa mea a primit un nume de SSID si o parola fixa indiferent ce cod de accesspoint  incarc. Ma poate ajuta cineva sa scap de numele si parola fixa? Mentionez ca am rescris inclusiv firmware-ul placi, dar tot asa merge. Banuiesc ca portiunea de cod care a generat problema este aceasta: 

 // Do a little work to get a unique-ish name. Append the
  // last two bytes of the MAC (HEX'd) to "Thing-":
  uint8_t mac[WL_MAC_ADDR_LENGTH];
  WiFi.softAPmacAddress(mac);
  String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) +
                 String(mac[WL_MAC_ADDR_LENGTH - 1], HEX);
  macID.toUpperCase();
  String AP_NameString = "ESP8266 Thing " + macID;

Va muultumesc.

Link to comment

Acest cod, la prima pornire,  face din esp8266 un acces point  la care te poti conecta pe web si scaneazi reteau existenta. Face o lista cu ap-urile existente si nivelul de semnal pentru fiecare. Daca alegi sa te conectezi la unul dintre ele, introduci parola de acces, daca are, si reteaua este salvata. esp8266 devine client la ap-ul memorat si la orice repornire se va conecta automat la ce are in memorie.Daca dupa un timp prestabilit nu se poate conecta la ap-ul din memorie se retransforma in ap si poti rescana reteau pentru un timp prestabilit. Nu stiu daca este ce iti doresti dar poti folosi portiuni de cod.

 

https://github.com/tzapu/WiFiManager

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines