ESP8266 not connecting to another ESP8266 - esp8266

I try to connect a few ESP8266 (STA-Mode) to one ESP8266 (AP Mode)
All of the ESP Stations connect well, but one will not connect.
The one can connect to other networks.
Debug Serial off well connecting ESPs:
15:03:31.355 -> fpm close 3
15:03:31.355 -> mode : sta(c8:c9:a3:57:c7:2e)
15:03:31.402 -> add if0
15:03:31.402 -> ..scandone
15:03:33.605 -> scandone
15:03:34.492 -> state: 0 -> 2 (b0)
15:03:34.492 -> state: 2 -> 3 (0)
15:03:34.492 -> state: 3 -> 5 (10)
15:03:34.492 -> add 0
15:03:34.492 -> aid 1
15:03:34.539 -> cnt
15:03:34.539 ->
15:03:34.539 -> connected with cardReaderConfig, channel 1
15:03:34.539 -> dhcp client start...
15:03:34.727 -> ip:10.10.10.101,mask:255.255.255.0,gw:10.10.10.1
15:03:34.727 -> WL-CONNECTED[HTTP] begin...
Debug Serial when I try to connect the one, which is failing:
15:28:39.458 -> fpm close 3
15:28:39.458 -> mode : sta(bc:ff:4d:f9:91:12)
15:28:39.458 -> add if0
15:28:39.458 -> ..scandone
15:28:43.785 -> scandone
15:28:43.785 -> no cardReaderConfig found, reconnect after 1s
15:28:43.926 -> reconnect
15:28:46.063 -> scandone
15:28:46.954 -> state: 0 -> 2 (b0)
15:28:46.954 -> state: 2 -> 3 (0)
15:28:46.954 -> state: 3 -> 5 (10)
15:28:46.954 -> add 0
15:28:46.954 -> aid 1
15:28:46.954 -> cnt
15:28:47.970 -> ..state: 5 -> 0 (0)
15:28:47.970 -> rm 0
15:28:50.176 -> scandone
15:28:52.353 -> scandone
15:28:52.353 -> no cardReaderConfig found, reconnect after 1s
15:28:52.446 -> reconnect
15:28:54.639 -> scandone
15:28:54.639 -> no cardReaderConfig found, reconnect after 1s
15:28:54.733 -> reconnect
15:28:56.136 -> ..scandone
15:28:58.347 -> scandone
15:29:00.531 -> scandone
15:29:00.531 -> no cardReaderConfig found, reconnect after 1s
15:29:00.612 -> reconnect
15:29:02.802 -> scandone
15:29:03.688 -> state: 0 -> 2 (b0)
15:29:03.688 -> state: 2 -> 3 (0)
15:29:03.688 -> state: 3 -> 5 (10)
15:29:03.688 -> add 0
15:29:03.688 -> aid 1
15:29:03.688 -> cnt
15:29:04.670 -> ..state: 5 -> 0 (0)
15:29:04.670 -> rm 0
When I try to connect to other networks, it works:
15:09:50.008 -> fpm close 3
15:09:50.008 -> mode : sta(bc:ff:4d:f9:91:12)
15:09:50.008 -> add if0
15:09:50.008 -> ..scandone
15:09:52.252 -> scandone
15:09:53.139 -> state: 0 -> 2 (b0)
15:09:53.139 -> state: 2 -> 3 (0)
15:09:53.139 -> state: 3 -> 5 (10)
15:09:53.139 -> add 0
15:09:53.139 -> aid 5
15:09:53.139 -> cnt
15:09:53.186 ->
15:09:53.186 -> connected with WLAN-AF, channel 6
15:09:53.186 -> dhcp client start...
15:09:53.232 -> ip:192.168.178.94,mask:255.255.255.0,gw:192.168.178.1
15:09:53.232 -> WL-CONNECTED[HTTP] begin...
Hope anyone can help, but assuming this is a hardware problem...
EDIT: I can connect via normal ESP8266Wifi (Wifi Client example script)
But get the error when trying via WifiMulti or Enterprise (BasicHttpClient example script).

Related

ejabberd two functions with same name

iam new in erlang and OTP i have two questions :
iam trying to read some erlang code from ejabberd source, it's very complex and iam surprised with two start/0 functions and two start/1 functions too in ejabberd_logger.erl so
1-what's this ? which function code will be executed when calling start/1?
2-should i read and understand all ejabberd source code to modify and customize it like i want ? i see that it's a huge code but is this a must for good handling ?
-module(ejabberd_logger).
-compile({no_auto_import, [get/0]}).
%% API
-export([start/0, get/0, set/1, get_log_path/0, flush/0]).
-export([convert_loglevel/1, loglevels/0]).
-ifndef(LAGER).
-export([progress_filter/2]).
-endif.
%% Deprecated functions
-export([restart/0, reopen_log/0, rotate_log/0]).
-deprecated([{restart, 0},
{reopen_log, 0},
{rotate_log, 0}]).
-type loglevel() :: none | emergency | alert | critical |
error | warning | notice | info | debug.
-define(is_loglevel(L),
((L == none) or (L == emergency) or (L == alert)
or (L == critical) or (L == error) or (L == warning)
or (L == notice) or (L == info) or (L == debug))).
-export_type([loglevel/0]).
%%%===================================================================
%%% API
%%%===================================================================
-spec get_log_path() -> string().
get_log_path() ->
case ejabberd_config:env_binary_to_list(ejabberd, log_path) of
{ok, Path} ->
Path;
undefined ->
case os:getenv("EJABBERD_LOG_PATH") of
false ->
"ejabberd.log";
Path ->
Path
end
end.
-spec loglevels() -> [loglevel(), ...].
loglevels() ->
[none, emergency, alert, critical, error, warning, notice, info, debug].
-spec convert_loglevel(0..5) -> loglevel().
convert_loglevel(0) -> none;
convert_loglevel(1) -> critical;
convert_loglevel(2) -> error;
convert_loglevel(3) -> warning;
convert_loglevel(4) -> info;
convert_loglevel(5) -> debug.
quiet_mode() ->
case application:get_env(ejabberd, quiet) of
{ok, true} -> true;
_ -> false
end.
-spec get_integer_env(atom(), T) -> T.
get_integer_env(Name, Default) ->
case application:get_env(ejabberd, Name) of
{ok, I} when is_integer(I), I>=0 ->
I;
{ok, infinity} ->
infinity;
undefined ->
Default;
{ok, Junk} ->
error_logger:error_msg("wrong value for ~ts: ~p; "
"using ~p as a fallback~n",
[Name, Junk, Default]),
Default
end.
-ifdef(LAGER).
-spec get_string_env(atom(), T) -> T.
get_string_env(Name, Default) ->
case application:get_env(ejabberd, Name) of
{ok, L} when is_list(L) ->
L;
undefined ->
Default;
{ok, Junk} ->
error_logger:error_msg("wrong value for ~ts: ~p; "
"using ~p as a fallback~n",
[Name, Junk, Default]),
Default
end.
-spec start() -> ok.
start() ->
start(info).
start(Level) ->
StartedApps = application:which_applications(5000),
case lists:keyfind(logger, 1, StartedApps) of
%% Elixir logger is started. We assume everything is in place
%% to use lager to Elixir logger bridge.
{logger, _, _} ->
error_logger:info_msg("Ignoring ejabberd logger options, using Elixir Logger.", []),
%% Do not start lager, we rely on Elixir Logger
do_start_for_logger(Level);
_ ->
do_start(Level)
end.
do_start_for_logger(Level) ->
application:load(sasl),
application:set_env(sasl, sasl_error_logger, false),
application:load(lager),
application:set_env(lager, error_logger_redirect, false),
application:set_env(lager, error_logger_whitelist, ['Elixir.Logger.ErrorHandler']),
application:set_env(lager, crash_log, false),
application:set_env(lager, handlers, [{elixir_logger_backend, [{level, Level}]}]),
ejabberd:start_app(lager),
ok.
do_start(Level) ->
application:load(sasl),
application:set_env(sasl, sasl_error_logger, false),
application:load(lager),
ConsoleLog = get_log_path(),
Dir = filename:dirname(ConsoleLog),
ErrorLog = filename:join([Dir, "error.log"]),
CrashLog = filename:join([Dir, "crash.log"]),
LogRotateDate = get_string_env(log_rotate_date, ""),
LogRotateSize = case get_integer_env(log_rotate_size, 10*1024*1024) of
infinity -> 0;
V -> V
end,
LogRotateCount = get_integer_env(log_rotate_count, 1),
LogRateLimit = get_integer_env(log_rate_limit, 100),
ConsoleLevel0 = case quiet_mode() of
true -> critical;
_ -> Level
end,
ConsoleLevel = case get_lager_version() >= "3.6.0" of
true -> [{level, ConsoleLevel0}];
false -> ConsoleLevel0
end,
application:set_env(lager, error_logger_hwm, LogRateLimit),
application:set_env(
lager, handlers,
[{lager_console_backend, ConsoleLevel},
{lager_file_backend, [{file, ConsoleLog}, {level, Level}, {date, LogRotateDate},
{count, LogRotateCount}, {size, LogRotateSize}]},
{lager_file_backend, [{file, ErrorLog}, {level, error}, {date, LogRotateDate},
{count, LogRotateCount}, {size, LogRotateSize}]}]),
application:set_env(lager, crash_log, CrashLog),
application:set_env(lager, crash_log_date, LogRotateDate),
application:set_env(lager, crash_log_size, LogRotateSize),
application:set_env(lager, crash_log_count, LogRotateCount),
ejabberd:start_app(lager),
lists:foreach(fun(Handler) ->
lager:set_loghwm(Handler, LogRateLimit)
end, gen_event:which_handlers(lager_event)).
-spec restart() -> ok.
restart() ->
Level = ejabberd_option:loglevel(),
application:stop(lager),
start(Level).
-spec reopen_log() -> ok.
reopen_log() ->
ok.
-spec rotate_log() -> ok.
rotate_log() ->
catch lager_crash_log ! rotate,
lists:foreach(
fun({lager_file_backend, File}) ->
whereis(lager_event) ! {rotate, File};
(_) ->
ok
end, gen_event:which_handlers(lager_event)).
-spec get() -> loglevel().
get() ->
Handlers = get_lager_handlers(),
lists:foldl(fun(lager_console_backend, _Acc) ->
lager:get_loglevel(lager_console_backend);
(elixir_logger_backend, _Acc) ->
lager:get_loglevel(elixir_logger_backend);
(_, Acc) ->
Acc
end,
none, Handlers).
-spec set(0..5 | loglevel()) -> ok.
set(N) when is_integer(N), N>=0, N=<5 ->
set(convert_loglevel(N));
set(Level) when ?is_loglevel(Level) ->
case get() of
Level ->
ok;
_ ->
ConsoleLog = get_log_path(),
QuietMode = quiet_mode(),
lists:foreach(
fun({lager_file_backend, File} = H) when File == ConsoleLog ->
lager:set_loglevel(H, Level);
(lager_console_backend = H) when not QuietMode ->
lager:set_loglevel(H, Level);
(elixir_logger_backend = H) ->
lager:set_loglevel(H, Level);
(_) ->
ok
end, get_lager_handlers())
end,
case Level of
debug -> xmpp:set_config([{debug, true}]);
_ -> xmpp:set_config([{debug, false}])
end.
get_lager_handlers() ->
case catch gen_event:which_handlers(lager_event) of
{'EXIT',noproc} ->
[];
Result ->
Result
end.
-spec get_lager_version() -> string().
get_lager_version() ->
Apps = application:loaded_applications(),
case lists:keyfind(lager, 1, Apps) of
{_, _, Vsn} -> Vsn;
false -> "0.0.0"
end.
-spec flush() -> ok.
flush() ->
application:stop(lager),
application:stop(sasl).
-else.
-include_lib("kernel/include/logger.hrl").
-spec start() -> ok | {error, term()}.
start() ->
start(info).
start(Level) ->
EjabberdLog = get_log_path(),
Dir = filename:dirname(EjabberdLog),
ErrorLog = filename:join([Dir, "error.log"]),
LogRotateSize = get_integer_env(log_rotate_size, 10*1024*1024),
LogRotateCount = get_integer_env(log_rotate_count, 1),
Config = #{max_no_bytes => LogRotateSize,
max_no_files => LogRotateCount,
filesync_repeat_interval => no_repeat,
file_check => 1000,
sync_mode_qlen => 1000,
drop_mode_qlen => 1000,
flush_qlen => 5000},
FmtConfig = #{legacy_header => false,
time_designator => $ ,
max_size => 100*1024,
single_line => false},
FileFmtConfig = FmtConfig#{template => file_template()},
ConsoleFmtConfig = FmtConfig#{template => console_template()},
try
ok = logger:set_primary_config(level, Level),
DefaultHandlerId = get_default_handlerid(),
ok = logger:update_formatter_config(DefaultHandlerId, ConsoleFmtConfig),
case quiet_mode() of
true ->
ok = logger:set_handler_config(DefaultHandlerId, level, critical);
_ ->
ok
end,
case logger:add_primary_filter(progress_report,
{fun ?MODULE:progress_filter/2, stop}) of
ok -> ok;
{error, {already_exist, _}} -> ok
end,
case logger:add_handler(ejabberd_log, logger_std_h,
#{level => all,
config => Config#{file => EjabberdLog},
formatter => {logger_formatter, FileFmtConfig}}) of
ok -> ok;
{error, {already_exist, _}} -> ok
end,
case logger:add_handler(error_log, logger_std_h,
#{level => error,
config => Config#{file => ErrorLog},
formatter => {logger_formatter, FileFmtConfig}}) of
ok -> ok;
{error, {already_exist, _}} -> ok
end
catch _:{Tag, Err} when Tag == badmatch; Tag == case_clause ->
?LOG_CRITICAL("Failed to set logging: ~p", [Err]),
Err
end.
get_default_handlerid() ->
Ids = logger:get_handler_ids(),
case lists:member(default, Ids) of
true -> default;
false -> hd(Ids)
end.
-spec restart() -> ok.
restart() ->
ok.
progress_filter(#{level:=info,msg:={report,#{label:={_,progress}}}} = Event, _) ->
case get() of
debug ->
logger_filters:progress(Event#{level => debug}, log);
_ ->
stop
end;
progress_filter(Event, _) ->
Event.
console_template() ->
[time, " [", level, "] " | msg()].
file_template() ->
[time, " [", level, "] ", pid,
{mfa, ["#", mfa, {line, [":", line], []}], []}, " " | msg()].
msg() ->
[{logger_formatter, [[logger_formatter, title], ":", io_lib:nl()], []},
msg, io_lib:nl()].
-spec reopen_log() -> ok.
reopen_log() ->
ok.
-spec rotate_log() -> ok.
rotate_log() ->
ok.
-spec get() -> loglevel().
get() ->
#{level := Level} = logger:get_primary_config(),
Level.
-spec set(0..5 | loglevel()) -> ok.
set(N) when is_integer(N), N>=0, N=<5 ->
set(convert_loglevel(N));
set(Level) when ?is_loglevel(Level) ->
case get() of
Level -> ok;
PrevLevel ->
?LOG_NOTICE("Changing loglevel from '~s' to '~s'",
[PrevLevel, Level]),
logger:set_primary_config(level, Level),
case Level of
debug -> xmpp:set_config([{debug, true}]);
_ -> xmpp:set_config([{debug, false}])
end
end.
-spec flush() -> ok.
flush() ->
lists:foreach(
fun(#{id := HandlerId, module := logger_std_h}) ->
logger_std_h:filesync(HandlerId);
(#{id := HandlerId, module := logger_disk_log_h}) ->
logger_disk_log_h:filesync(HandlerId);
(_) ->
ok
end, logger:get_handler_config()).
-endif.
Here, the first version is protected by -ifdef(LAGER). and thus gets used if the macro LAGER is defined, and the second version comes after '-else.', and gets used if LAGER is not defined. (The first version uses the Lager library for logging, and the second version uses the newer built-in logger library.)

How do I check if grammar is SLR(1)?

How do I check if this grammar is SLR(1)?
S' -> S
S -> [ B
A -> int
A -> [ B
B -> ]
B -> C
C -> A ]
C -> A , C
First I've created it's automaton, then computed the follow sets for non-terminals and then created the parsing table.
I'm not sure if my automaton is correct, but after doing the parsing table for SLR(1) grammar I did not find any errors.
Below is my attempt at the automaton.
I0:
S' -> .S
S -> .[B
I1 (I0 -> S):
S -> [.B
B -> .]
B -> .C
C -> .A]
C -> .A,C
A -> .int
A -> .[B
I3 (I2 -> B)
S -> [B.
I4 (I2 -> ])
B -> ].
I5 (I2 -> C)
B -> C.
I6 (I2 -> A)
C -> A.]
C -> A.,C
I7 (I2 -> int)
A -> int.
I8 (I2 -> [)
A -> [.B
B -> .]
B -> .C
C -> .A]
C -> .A,C
A -> .int
A -> .[B
I8 -> ] = I4
I8 -> C = I5
I8 -> A = I6
I8 -> int = I7
I8 -> [ = I8
I9 (I6 -> ])
C -> A].
I10 (I6 -> ,)
C -> A,.C
C -> .A]
C -> .A,C
A -> .int
A -> .[B
I11 (I8 -> B)
A -> [B.
I12 (I10 -> C)
C -> A,C.
I10 -> A = I6
I10 -> int = I7
I10 -> [ = I8
Considering that you have done the hard work, to find all the states, now it is time to check the Rules of SLR(1).
https://en.wikipedia.org/wiki/SLR_grammar
As you can realize, your question misses the Follow() set which is mandatory in the Rules.
Yes, you can find out on your table parser if there is a conflict or not, but this is an answer depended more on experience than actual science.
Check the Rules one-by-one and you will be fine :)
Depending on the fact that you are sure about the correctness of your states, I see no Shift/Reduce or Reduce/Reduce conflict, so the Grammar is SLR(1)

Match within a match?

Is there a way to do a match within a match in F#? I've noticed that you can do one tailed on another like so...
match L.Head with
| null -> []
| _ -> match N with
| 1 -> [L.Head]
| _ -> []
But is there a way to do it so that a match, ending with a _ can be placed in the MIDDLE of another match? This seems to give a bug... is there a better way to do this, should you need it for your logic? EX:
match A with
| 0 -> match B with
| 1 -> 1
| _ -> 0
| _ -> 2
Why not use match on a tuple -
match (A,B) with
|0,1 -> 1
|0,_ -> 0
|_, -> 2
Not sure whether it was possible 7 years ago, but now you can use struct to reduce allocations:
match struct (A, B) with
| 0, 1 -> 1
| 0, _ -> 0
| _ -> 2
Old answer creates instance of System.Tuple`2, while this creates instance of System.ValueTuple`2
Decompilation

Neo4j Cypher Bus Route Selection

I am new to Cypher, I would like to know whether the following case is possible in Neo4j Cypher:
When I want to query what the buses should be taken from Station 1 to Station 4, the output should be (which consists of least number of interchange):
Station 1 -> route 1 -> Station 3 -> route 3 -> station 4
Station 1 -> route 2 -> Station 3 -> route 3 -> station 4
But not every possible combinations:
Station 1 -> route 1 -> Station 2 -> route 1 -> Station 3 -> route 3 -> station 4
Station 1 -> route 1 -> Station 2 -> route 2 -> Station 3 -> route 3 -> station 4
Station 1 -> route 2 -> Station 2 -> route 1 -> Station 3 -> route 3 -> station 4
Station 1 -> route 2 -> Station 2 -> route 2 -> Station 3 -> route 3 -> station 4
Thanks!
This is difficult without conditional expressions (CASE/WHEN is now in 2.0). This is as close as I got in my few minutes of trying. You'd have to pull out the start nodes from the resulting relationship collection.
start st1=node:node_auto_index(name="station1"), st4=node:node_auto_index(name="station4")
match p=st1-[r*]->st4
with reduce(acc=[], route in rels(p):
case
when length(acc) > 0 and last(extract(a in acc: a.name)) = route.name then acc
else acc + route
end) as reducedRoutes
return reducedRoutes, length(reducedRoutes) as len
order by len;
http://console.neo4j.org/r/koe6fo

how to backup/restore only single table from/to mnesia?

I have some big tables with disc_only_copies type.
Now I need change short node name to long but cannot do it with RAM limitation...
Can I use backup/restore database partly (table by table)?
-module(test).
-compile(export_all).
-record(tab, {first, second}).
do() ->
mnesia:create_schema([node()]),
mnesia:start(),
mnesia:create_table(tab, [{disc_copies, [node()]}, {attributes, record_info(fields, tab)}]),
mnesia:dirty_write({tab, 1, 2}),
mnesia:dirty_write({tab, a, b}),
mnesia:stop().
change_node('extra#localhost') ->
'extra#example.com';
change_node('ejabberd#localhost') ->
'ejabberd#example.com';
change_node(Node) ->
Node.
handle_nodes(Nodes) ->
lists:map(fun(Node) ->
change_node(Node)
end, Nodes -- [one#badhost, extra#badhost]).
handle_cookie({TS, Node}) ->
{TS, change_node(Node)}.
handle_version_value([]) ->
[];
handle_version_value({'one#badhost', _}) ->
[];
handle_version_value({'extra#badhost', _}) ->
[];
handle_version_value({Node, TS}) ->
{change_node(Node), TS}.
handle_version({Key, Value}) ->
{Key, handle_version_value(Value)}.
handle_def(Def) ->
lists:map(fun({Key, Value} = Property) ->
case Key of
ram_copies ->
{Key, handle_nodes(Value)};
disc_copies ->
{Key, handle_nodes(Value)};
disc_only_copies ->
{Key, handle_nodes(Value)};
cookie ->
{Key, handle_cookie(Value)};
version ->
{Key, handle_version(Value)};
_ ->
Property
end
end, Def).
go() ->
{ok, N} = dets:open_file(schema, [{file, "./schema.DAT"},{repair,false}, {keypos, 2}]),
do2(N),
dets:sync(N),
dets:close(N).
do2(N) ->
do2(N, dets:first(N)).
do2(_N, '$end_of_table') ->
ok;
do2(N, Key) ->
io:format("process: ~p~n", [Key]),
[{N, Tab, Def}] = dets:lookup(N, Key),
NewDef = handle_def(Def),
dets:insert(N, {N, Tab, NewDef}),
% file:write_file("schema.txt", io_lib:format("~p~n", [{N, Tab, NewDef}]), [append]),
do2(N, dets:next(N, Key)).

Resources